我對標籤有點擊功能。我想在同一個元素上綁定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
沒問題,請參閱下面的答案。 –