button onclick function firing twice

后端 未结 7 1595
天涯浪人
天涯浪人 2020-12-08 00:20

I have a button that calls a javascript function using an event handler. For some reason, the event handler is being called twice.

Here is my button (I am using a ph

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 01:10

    Unbind event from selector and after appending in element in DOM again trigger event on specific selector.. $("selector_name").unbind( "event" ); //After this call event on selector again..

    For example:

    $( "#button" ).unbind( "click" );
    
    $("#button").click(function(event) {
    console.log("button click again);
    });
    

提交回复
热议问题