JQuery Unbind and then bind

后端 未结 3 741
萌比男神i
萌比男神i 2020-12-11 13:03

I\'ve found lots of examples on this topic.. however, I do not fully understand. Does my logic seem correct? I have a div as button (class of .myClass) and I don\'t want i

3条回答
  •  长情又很酷
    2020-12-11 13:34

    I'm not sure exactly what you're trying to achieve, but .unbind() removes all handlers attached to the element when called with no arguments. Therefore, $('.myClass').unbind() removes all event handlers attached to the elements with a class of .myClass. Since you only seem to be adding one event handler, click, it would be better to only unbind the click handler, like so: $('.myClass').unbind('click'). This way you won't be confused why other events are being unbinded if you add additional events later on.

提交回复
热议问题