<button>btn01</button>
<button>btn02</button>
<button>btn03</button>
<script src="./js/jquery-3.1.1.js"></script>
<script>
//元素集合.each() 用来遍历获取的元素集合
/*$('button').each(function(){
//this是js中的对象
console.log(this.innerHTML)
})*/
//function中自带了两个参数(可省略不写,写一个代表下标)
$('button').each(function(index,element){
console.log(index,element.innerHTML);
})
//$.each() 用于遍历集合对象,例如:数组、json对象等
let arr = ["haha","hehe"];
$.each(arr,function(index,val){
console.log(index,val);
})
let json = {"name":"小黑","age":13}
$.each(json,function(key,val){
console.log(key,val);
})
</script>
jQuery遍历
最新推荐文章于 2024-07-19 03:08:33 发布