jQuery的循环的那些事儿

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>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值