jQuery change event being called twice

后端 未结 9 1066
滥情空心
滥情空心 2020-12-05 23:03

I have a form with some input and select boxes, each has class=\"myClass\". I also have the following script:

$(document).ready(function() {
            


        
相关标签:
9条回答
  • 2020-12-05 23:14

    if this occurred in IE, it may be this bug as it was for me: http://bugs.jquery.com/ticket/6593

    updating to jQuery 1.7.1 worked for me.

    0 讨论(0)
  • 2020-12-05 23:20

    For me - I had written the on change event inside a function. Moving it to $(document).ready(function () {}); solved my case.

    0 讨论(0)
  • 2020-12-05 23:21

    Try debugging the code in Firebug rather than alerting. It may be loosing the focus and returning it is causing the appearance of two changes when there isn't two happening

    0 讨论(0)
  • 2020-12-05 23:22

    All I can think of is that you used the same class on the form itself. if so, remove the myClass style from your form tag.

    Corrected : http://jsfiddle.net/rY6Gq/1/

    Faulty one with double alert: http://jsfiddle.net/rY6Gq/

    0 讨论(0)
  • 2020-12-05 23:24

    It isn't: http://jsfiddle.net/nfcAS/

    0 讨论(0)
  • 2020-12-05 23:25

    e.stopImmediatePropagation(); is what worked for me.

    $(document).ready(function() {
        $(".myClass").change(function(e) {
            e.stopImmediatePropagation();
            alert('bla');
        })
    });
    
    0 讨论(0)
提交回复
热议问题