button onclick function firing twice

后端 未结 7 1591
天涯浪人
天涯浪人 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:09

    Maybe you are attaching the event twice on the same button. What you could do is unbind any previously set click events like this:

    $('.addToCartButton').unbind('click').click(function() {
        alert("bob");
        //addToCart($(this).attr("id"));
    });
    

    This works for all attached events (mouseover, mouseout, click, ...)

提交回复
热议问题