JQuery鼠标悬停功能发射多次

JQuery鼠标悬停功能发射多次

本文介绍了JQuery鼠标悬停功能发射多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用这种方法很长时间来为整个类(按钮等)设置事件:

  $ (div.bigButton)。mouseover(function(){this.style.backgroundColor ='#dfdfdf';}); 

但是,在做一些测试的时候,我注意到当把鼠标移动到这些对象上时,函数fires 3次!这是不可见的,当更改的东西像backgroundColor,但如果我添加一个警报,这是非常明显的。



任何想法我做错了什么?

感谢



编辑:对不起,遗漏了样式是一个拼写错误



HTML是:

  ; div class =bigButton> 
Test< / div>


解决方案

我发现 (每次通过ajax发送页面内容时)。我会认为这会覆盖'mouseover'功能,但它似乎添加到它。



感谢您的帮助


I have been using this method for a long time to set events for entire classes (for buttons etc):

$("div.bigButton").mouseover(function() { this.style.backgroundColor = '#dfdfdf'; });

However while doing some testing I have just noticed that when moving the mouse over these objects, the function fires 3 times! This is unnoticable when changing something like backgroundColor, but if I add an alert it's very obvious.

Any ideas what I'm doing wrong? I am concerned this may have an impact on performance later on.

Thanks

EDIT: Sorry, missing "style" off was a typo

The HTML is:

<div class="bigButton">
Test</div>
解决方案

I have discovered that the function that sets up the buttons was being run multiple times (each time the page content was delivered via ajax). I would have thought this would overwrite the 'mouseover' function, but it seems it was adding to it instead!

Thanks for all your help

这篇关于JQuery鼠标悬停功能发射多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:24