jQuery click event handler is called twice for a checkbox

前端 未结 10 1940
野趣味
野趣味 2020-12-09 17:08

I have a problem with the following code in an ASPX page:



        
10条回答
  •  执念已碎
    2020-12-09 17:36

    Solved: this to work with Firefox 3.6.12 and IE8.

    $(function(){
            $("form input:checkbox").unbind("click")
            .click(function(){
                val = $(this).val();
                alert(val);
            })
        }
    

    The trick is to unbind("click"). before bind it to .click(fn); this will disabled the same event to fire twice.

    Note that event "change" will not tricker at first time checkbox has been checked. So I use "click" instead.

提交回复
热议问题