1、遍历元素下所有子元素 (不包括孙子级)
$("#taskPropertyForm").children().each(function (i, item) {
var $this = $(item);
var _this = item;
console.log(i);
console.log(item.tagName);
});
2、遍历元素下所有的子元素(包括所有子级,孙子及。。。)
$("#taskPropertyForm").find("*").each(function (i, item) {
var $this = $(item);
var _this = item;
console.log(i);
console.log(item.tagName);
});
3、遍历对象
var b = new Object;
b.property = [{
"id": "f_p_id",
"text": "span",
"value": "1111"
}, {
"id": "f_p_name",
"text": "input",
"value": "222222"
}, {
"id": "f_p_info",
"text": "textarea",
"value": "333333"
}];
$.each(b.property, function (i, item) {
console.log(item);
});
// b.property.forEach(function () {
// console.log($(this).id);
// });
4、js遍历对象
var objn = {};
objn.nodes = {};
for (i in obj.nodes) {
// console.log(obj.nodes[i]);
var nodes = {};
objn.nodes[obj.nodes[i].id] = {
"name": obj.nodes[i].name,
"id": obj.nodes[i].id
}
}