复选框绑定CHANGE事件

8

当用户点击/触摸复选框后,我希望提交我的表单:

HTML 代码:

<input type="checkbox" name="chkSales" id="chkSales" class="custom" data-inline="true" data-mini="true"/><label for="chkSales">Sales</label>                                         
<input type="checkbox" name="chkArrival" id="chkArrival" class="custom" data-inline="true" data-mini="true"/><label for="chkArrival">New Arrival</label>                                                         

Js:

$("input[type='checkbox']").change(function() {
    alert(e);
    print(e);
});​

根据我在这里阅读的内容,它应该是可以工作的,但事实并非如此!我的问题出在哪里呢?

(由于移动设备不是通过点击而是通过触摸来操作,所以应该进行更改... http://jsfiddle.net/usTHG/2/

3个回答

19
$("input[type='checkbox']").change(function(e) {
                                            ^---- you missed e here
    alert(e.type); 
    print(e);
});​

工作示例


3
请尝试这个:
在您的函数(e)中缺少e代码
$("input[type='checkbox']").change(function(e) {
    alert(e);
    print(e);
});​

1

尝试:

$(document).ready(function() {
        $("input[type='checkbox']").change(function(e) {
            alert(e);
            print(e);
        });
    });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接