Bind JavaScript jQuery click event on label AND on checkbox simultaneously

前端 未结 2 894
夕颜
夕颜 2021-01-11 10:54

I\'m using labels for my form, like this :



相关标签:
2条回答
  • 2021-01-11 11:12

    Instead of binding with the click() event, you should bind using the change() event, then however this change is triggered the outcome will be the same:

    $('#foo').change(
        function(){
            // do whatever
        });
    

    References:

    • change().
    0 讨论(0)
  • 2021-01-11 11:31

    The change event should fire for the input whether the label or input is clicked:

    $("#foo").change(function () { ... });
    

    Example http://jsfiddle.net/andrewwhitaker/6LMXW/

    0 讨论(0)
提交回复
热议问题