jQuery 复选框绑定 CHANGE 事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11114056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:12:39  来源:igfitidea点击:

Checkbox bind CHANGE event

jqueryeventsbind

提问by ItsMeDom

I want to submit my form after a user clicked/touched the checkbox:

我想在用户单击/触摸复选框后提交我的表单:

THE HTML

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>                                                         

? The Js:

? Js:

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

From what I read here it should really work, but id doenst! where is my problem?

从我在这里读到的内容来看,它应该确实有效,但我确实如此!我的问题在哪里?

(it should be change, since mobile devices don't click, they use touch... http://jsfiddle.net/usTHG/2/

(应该改变,因为移动设备不点击,他们使用触摸...... http://jsfiddle.net/usTHG/2/

回答by thecodeparadox

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

Working example

工作示例

回答by Tats_innit

Try this please:

请试试这个:

you are missing ein your function(e)

e在你的函数中缺少(e

code

代码

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

回答by Mantas Vaitkūnas

try:

尝试:

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