JQuery如何将click事件绑定到所有复选框

mom*_*raw 2 jquery

我有这样的多个复选框

<input name="1[]" type="checkbox">
<input name="1[]" type="checkbox">
<input name="2[]" type="checkbox">
<input name="2[]" type="checkbox">
<input name="3[]" type="checkbox">
<input name="4[]" type="checkbox">
Run Code Online (Sandbox Code Playgroud)

如何将onclick绑定到所有这些复选框.并运行一个函数..让我们说一个提示"你单击列出的复选框之一"

 $("input").click() {

            return confirm("you click one of the listed checkbox?");

    });
Run Code Online (Sandbox Code Playgroud)

这不起作用

tym*_*eJV 5

你需要使它成为点击的功能

$('input[type="checkbox"]').click(function() {
    alert("you click one of the listed checkbox?");
});
Run Code Online (Sandbox Code Playgroud)

摆弄:http://jsfiddle.net/XQDfP/