button onclick function firing twice

后端 未结 7 1586
天涯浪人
天涯浪人 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 00:56

    You probably want to pass in the event and add

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

    OR

    $('.addToCartButton').click(function(e) {
      e.preventDefault(); //Added this
      alert("bob");
      //addToCart($(this).attr("id"));
      return false;
    });
    

提交回复
热议问题