判断复选框哪一个被点击
<!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>

相关文章:

  • 2022-12-23
  • 2021-05-12
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2021-12-12
猜你喜欢
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-08-12
相关资源
相似解决方案