jquery:绑定多个事件,然后取消绑定其中几个?这是对的吗?
绑定多个事件,然后取消绑定其中几个?这是对的吗?
基本上,当您将鼠标悬停在元素上时,背景颜色会发生变化,然后当您将鼠标悬停在元素之外时又变回来,但是当您单击该元素时,我想禁用悬停效果并将背景颜色更改为不同的颜色,以便用户知道他们点击了它。最好的方法是什么?谢谢!
$('.tellmereplies').bind({click: function() {
$(this).animate({'backgroundColor':'#0099ff', 'color':'#fff'})
$('.tellmereplies').unbind('mouseover','mouseout')
},mouseover: function() {
$(this).animate({'backgroundColor':'#fbca54', 'color':'#fff'})
},mouseout: function() {
$(this).animate({'backgroundColor':'#E4E4E4', 'color':'#c0c0c3'})
}
});
bind multiple events, then unbind a couple of them? is this right?
basically when you hover over the element, the background color changes, then changes back when you hover out of the element, but when you click the element i want to disable the hover effect and change the background color to a different color so the user knows that they clicked on it. what's the best way to do this? thanks!
$('.tellmereplies').bind({click: function() {
$(this).animate({'backgroundColor':'#0099ff', 'color':'#fff'})
$('.tellmereplies').unbind('mouseover','mouseout')
},mouseover: function() {
$(this).animate({'backgroundColor':'#fbca54', 'color':'#fff'})
},mouseout: function() {
$(this).animate({'backgroundColor':'#E4E4E4', 'color':'#c0c0c3'})
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下 jquery 的事件命名空间。我想这可能对你有用。
Take a look at jquery's event namespacing. I think that is probably going to be useful to you.
我想你正在寻找这个:
I think you're looking for this:
我主要用 CSS 来做这件事。您可以使用 :hover 伪类为链接创建悬停效果。
然后,当用户单击链接时,向链接添加另一个类值并覆盖链接的悬停效果。
I'd do this mainly in CSS. You can create the hover effects for your links using the :hover pseudo-class
Then when the user clicks on the link, add another class value to the link and override the hover effects for the link.