Jquery 检查已选中的复选框

Jquery 检查已选中的复选框,jquery,html,checkbox,Jquery,Html,Checkbox,所以我有一个带有9个复选框的html。我正在尝试使用JQuery检查它们何时被检查/切换。这是我当前的代码 <script> $(document).ready(function(){ $("input[type=checkbox]").change(function() { alert("Checked"); }); }); </script> $(文档

所以我有一个带有9个复选框的html。我正在尝试使用JQuery检查它们何时被检查/切换。这是我当前的代码

<script>
        $(document).ready(function(){
            $("input[type=checkbox]").change(function() {
                alert("Checked");

            });
        });
</script>

$(文档).ready(函数(){
$(“输入[type=checkbox]”)。更改(函数(){
警报(“已检查”);
});
});
这是我的html设置:

<form method="post">
    <input type="checkbox" id="1" name="1"/>
        <label for="1"><span>1</span></label>
    <input type="checkbox" id="2" name="2"/>
        <label for="2"><span>2</span></label>
    <input type="checkbox" id="3" name="3"/>
        <label for="3"><span>3</span></label>
    <input type="checkbox" id="4" name="4"/>
        <label for="4"><span>4</span></label>
    <input type="checkbox" id="5" name="5"/>
        <label for="5"><span>5</span></label>
    <input type="checkbox" id="6" name="6"/>
        <label for="6"><span>6</span></label>
    <input type="checkbox" id="7" name="7"/>
        <label for="7"><span>7</span></label>
    <input type="checkbox" id="8" name="8"/>
        <label for="8"><span>8</span></label>
    <input type="checkbox" id="9" name="9"/>
        <label for="9"><span>9</span></label>
</form>

1.
2.
3.
4.
5.
6.
7.
8.
9
上述代码没有警报输出。怎么了?

喜欢吗

    $(document).ready(function(){
        $("input[type=checkbox]").click(function() {
             if($(this).prop("checked"))
                alert("Checked");

        });
    });
是一把演示小提琴

试试这个

$(document).ready(function() {

    $("input[type='checkbox']").change(function() {
        if($(this).is(":checked")) {
             alert("Checked");
        }     
    });
});

使用
属性
选择器和
:checked
选择器获取输入。然后使用
.each()

JS Fiddle:

似乎很好用。
$(document).ready(function () {
    $("input[type=checkbox]").change(function () {
        if(this.checked){
            alert('checked');
        }
    });
});
$(document).ready(function() {

    $("input[type='checkbox']").change(function() {
        if($(this).is(":checked")) {
             alert("Checked");
        }     
    });
});
$("input[type='checkbox']:checked").each(function(i,e){
    alert(e.id);
});