首页 > 其他 > 详细

判断复选框是否点击和点击了哪一个

时间:2016-08-26 01:16:04      阅读:202      评论:0      收藏:0      [点我收藏+]
判断复选框哪一个被点击
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
var a=$(‘[type=checkbox]‘).length;
alert(a);
for(var i=0;i<a;i++){
 if($(‘[type=checkbox]‘).eq(i).is(‘:checked‘)) {
         alert(i+1);  
    }
}
});
});
</script>
</head>
<body>
<input type="checkbox" class="a">123
<input type="checkbox" class="b">123
<button>获取被点击的按钮</button>
</body>
</html>
 
只要复选框被点击,不管哪一个都出发事件。
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
 if($(‘[type=checkbox]‘).is(‘:checked‘)) {
         alert(true);  
}
});
});
</script>
</head>
<body>
<input type="checkbox" class="a">123
<input type="checkbox" class="b">123
<button>获取被点击的按钮</button>
</body>
</html>

判断复选框是否点击和点击了哪一个

原文:http://www.cnblogs.com/jiaxin/p/5808824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!