本文介绍了jQuery checkbox事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下:

 < form id =myform> 
< input type =checkboxname =check1value =check1>
< input type =checkboxname =check2value =check2>
< / form>

如何使用jQuery捕获<$> 检查事件发生在<$

解决方案

c $ c> myform
并告诉哪个复选框被切换div(

  $('#myform:checkbox'))change(function(){
//这将包含对复选框的引用
if this.checked){
//复选框现在被选中
} else {
//复选框现在不再被选中
}
});


I have the following:

<form id="myform">
   <input type="checkbox" name="check1" value="check1">
   <input type="checkbox" name="check2" value="check2">
</form>

How do I use jQuery to capture any check event occuring in myform and tell which checkbox was toggled (and know if it was toggled on or off)?

解决方案
$('#myform :checkbox').change(function() {
    // this will contain a reference to the checkbox
    if (this.checked) {
        // the checkbox is now checked
    } else {
        // the checkbox is now no longer checked
    }
});

这篇关于jQuery checkbox事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:25