我对标签有点击功能。我想在同一个元素上绑定mouseover事件。这可能与.bind方法。 fiddle在jquery中绑定事件
$(function(){
$('a').click(function(){
alert(0);
})
$('a').bind('mouseover')
})
<a href="#">Jitender</a>
我对标签有点击功能。我想在同一个元素上绑定mouseover事件。这可能与.bind方法。 fiddle在jquery中绑定事件
$(function(){
$('a').click(function(){
alert(0);
})
$('a').bind('mouseover')
})
<a href="#">Jitender</a>
是的。只要绑定之后点击绑定鼠标悬停:
$('a').click(function(){
alert(0);
}).bind('mouseover', function() {
$(this).css('background-color', 'red'); // To show it working
});
您应该使用on
关键字。
$('a').on('mouseover', function() { alert(1);})
“在jQuery 1.7中,。对()方法是事件处理程序的 附着于文档的首选方法。”
假设你要绑定的相同的处理到click
和mouseover
事件中,你可以试试这个:
$('a').on('click mouseover', function(e) {
e.preventDefault();
alert('0');
});
注的用法on
优于jQuery 1.7+中的bind
。
你的意思是你想在'click'和'mouseover'上运行相同的事件处理程序吗? –
@RoryMcCrossan:是的 – Carlos
没问题,请参阅下面的答案。 –