JavaScript/jQuery: event fired twice

后端 未结 2 1350
梦如初夏
梦如初夏 2020-12-21 15:01

I\'m trying some event bindings with jQuery, and I have this simple code in my document ready:

$(document).ready(function() {
    $(\"p a\").each(function(i,         


        
相关标签:
2条回答
  • 2020-12-21 15:41

    I suppose this doesn't answer your question, but this post came up while researching my own bug. It turned out the problem was that I had inadvertently included an external javascript twice.

    Just thought it would be worthwhile to document this for others who have the same problem. An obvious error that took a while to track down!

    0 讨论(0)
  • 2020-12-21 15:45

    I think somehow the alert is actually causing the extra events in Chrome. With the following code I only see one event.

    $(document).ready(function() {
      $("p a").each(function(i, selected){
        $(selected).hover( 
          function(event) { $("p").append('<br>over: ' + event.type); }, 
          function(event) { $("p").append(' out: ' + event.type); });
        }
      )
    });
    
    0 讨论(0)
提交回复
热议问题