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、es6
var obj=arr.find(function (obj) {
return obj.id === 3
})
array.forEach(function(v){ console.log(v); });
Array.forEach(function(value , index , array){ //value为遍历的当前元素,index为当前索引,array为正在操作的数组 //do something },thisArg) //thisArg为执行回调时的this值
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 } }
5、
$(".J_menuTab.active")
class="J_menuTab active"