1.
要遍历的jQuery对象.each(function(){
.....
})
要遍历的jQuery对象.each(function(参数1,参数2){
.....
})
2.
$.each(要遍历的jQuery对象,funcation(){
......
})
$.each(要遍历的jQuery对象,funcation(参数1,参数2){
......
})
注:
1.参数1表示索引,参数2表示遍历到的每个对象
2.参数1和参数2的形参名是任意的
3.没有参数的函数,在遍历过程中,可以通过this表示每次遍历得到的对象
4.在函数中使用return false 表示break、使用return true 表示continue
3.
for(临时变量 of 要遍历的jQuery对象){
....
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-2.2.4.min.js">
</script>
<script type="text/javascript">
$(function(){
var $options = $("#left > option")
// $options.each(function(){
// alert($(this).html());
// })
// $.each($options, function() {
//
// alert($(this).html());
//
// });
// $options.each(function(a,b){
// alert(a+"-----------------"+$(b).html());
// })
$.each($options, function(index,object) {
alert(index+"------------------"+$(object).html());
});
})
</script>
</head>
<body>
<select id="left" multiple>
<option>11111</option>
<option>22222</option>
<option>3333</option>
<option>44444</option>
<option>55555</option>
</select>
</body>
</html>