近期在项目开发中需要页面回车切换文本焦点顾如下:
$('input:text:first').focus(); //获取页面所有文本
var $inp = $('input:text');
$inp.bind('keydown', function (e) {
var key = e.which;
if (key == 13) {
e.preventDefault();
var nxt = $inp.index(this) + 1;
$(":input:text:eq(" + nxt + ")").focus();
}
});
本文链接
转自:http://blog.csdn.net/on_my_way20xx/article/details/7791769
$.each()
- Posted on 2012 年 3 月 15 日 in jQuery, jQuery函数
- |
- by Jason
- |
译自官方手册:jQuery.each()
对数组或对对象内容进行循环处理
jQuery.each( collection, callback(indexInArray, valueOfElement) )
collection 遍历的对象或数组
callback(indexInArray, valueOfElement) 在每一个对象上调用的函数
说明
一个通用的遍历函数 , 可以用来遍历对象和数组. 数组和含有一个length属性的伪数组对象 (伪数组对象如function的arguments对象)以数字索引进行遍历,从0到length-1, 其它的对象通过的属性进行遍历.
$.each()与$(selector).each()不同, 后者专用于jquery对象的遍历, 前者可用于遍历任何的集合(无论是数组或对象),如果是数组,回调函数每次传入数组的索引和对应的值(值亦可以通过this 关键字获取,但javascript总会包装this 值作为一个对象—尽管是一个字符串或是一个数字),方法会返回被遍历对象的第一参数
2 <!DOCTYPE html>
3 <html>
4 <head>
5 <script src=/blog_article/”http_/code.jquery.com/jquery-latest.js”></script>_br/index.html> 6 </head>
7 <body>
8 <script>
9 $.each([52, 97], function(index, value) {
10 alert(index + ‘: ‘ + value);
11 });
12 </script>
13 </body>
14 </html>
15 //输出
16 0: 52
17 1: 97
2 <!DOCTYPE html>
3 <html>
4 <head>
5 <script src=/blog_article/”http_/code.jquery.com/jquery-latest.js”></script>_br/index.html> 6 </head>
7 <body>
8 <script>
9 var map = {
10 ‘flammable’: ‘inflammable’,
11 ‘duh’: ‘no duh’
12 };
13 $.each(map, function(key, value) {
14 alert(key + ‘: ‘ + value);
15 });
16 </script>
17 </body>
18 </html>
19 //输出
20 flammable: inflammable
21 duh: no duh
2 <!
<!--
var userGroup;
var CanAddDeleteComponent;
var setting = {
// async: {
// enable: true,
// url: '<%= Url.Action("GetTree") %>',
// autoParam: ["id", "pId", "name=n", "level=lv"],
// otherParam: { "productId": '1' }
//// otherParam: { "otherParam": "zTreeAsyncTest" },
//// dataFilter: filter
// },
view: {
addHoverDom: addHoverDom,
removeHoverDom: removeHoverDom,
selectedMulti: false
},
// check: {
// enable: true
// },
edit: {
enable: true,
editNameSelectAll: true,
//showRenameBtn: setRenameBtn,
showRenameBtn: false,
showRemoveBtn: setRemoveBtn
},
data: {
simpleData: {
enable: true
}
},
callback: {
beforeDrag: beforeDrag,
beforeEditName: beforeEditName,
beforeRemove: beforeRemove,
beforeRename: beforeRename,
onRemove: onRemove,
onRename: onRename
}
};
// var zNodes = [
// { id: 1, pId: 0, name: "Parent Node 1", open: true },
// { id: 11, pId: 1, name: "2nd Level 1-1", open: true },
// { id: 111, pId: 11, name: "3nd Level 1-1-1" },
// { id: 112, pId: 11, name: "3nd Level 1-1-2" },
// { id: 12, pId: 1, name: "2nd Level 1-2" },
// { id: 121, pId: 12, name: "3nd Level 1-1-1" },
// { id: 122, pId: 12, name: "3nd Level 1-1-2" },
// { id: 13, pId: 1, name: "2nd Level 1-3" }
// ];
function filter(treeId, parentNode, childNodes) {
if (!childNodes) return null;
for (var i = 0, l = childNodes.length; i < l; i++) {
childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
var log, className = "dark";
function beforeDrag(treeId, treeNodes) {
return false;
}
function beforeEditName(treeId, treeNode) {
className = (className === "dark" ? "":"dark");
showLog("[ "+getTime()+" beforeEditName ] " + treeNode.name);
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.selectNode(treeNode);
return confirm("Edit Node -- " + treeNode.name + "?");
}
function beforeRemove(treeId, treeNode) {
className = (className === "dark" ? "" : "dark");
showLog("[ " + getTime() + " beforeRemove ] " + treeNode.name);
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.selectNode(treeNode);
//confirm("Are you sure to DELETE node -- " + treeNode.name + " ?")
var canDelete;
$.ajax({
url: '<%=Url.Action("CanDeleteTreeNode")%>',
type: 'POST',
async: false,
data: { productId: $('#ProductsDropDownList').val(), treenodeId: treeNode.id },
success: function (data) {
if (data == "0") {
alert("Node is NOT allowed to delete since there is product definition for the node.");
canDelete=false;
} else {
canDelete = true;
}
}
});
return canDelete;
}
function onRemove(e, treeId, treeNode) {
showLog("[ " + getTime() + " onRemove ] " + treeNode.name);
}
&