jQuery change event being called twice

后端 未结 9 1067
滥情空心
滥情空心 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:27

    The only one that worked for me was unbind before the change check.

     $(".select2Component").unbind(); 
        $(".select2Component").change(function() { 
             //code
        });
    
    0 讨论(0)
  • 2020-12-05 23:28

    It happens when the same class or whatever attribute you are binding also has the same name parent or child. Obviously, when you change a child, parent also gets changed (its child changes). If they have the same class or attribute, it should fire twice. For example, in the following if you bind to "myClass", it will be called twice.

    <div class="myclass">
    <select class="myClass">   </select>
    </div>
    
    0 讨论(0)
  • 2020-12-05 23:35

    Its a bug, You'd add

    $("#some_id").unbind('change');
    

    before any change call

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