[英]How can I fix this jQuery glitch so the div doesn't try to disappear when using .hover()?
[英]jQuery .click doesn't work when also using .hover , how can I fix this?
我正在使用下面的代碼,.click操作本身可以正常工作,一旦添加.hover,.hover就會起作用,而.click會停止工作。 任何想法為什么會發生這種情況以及如何解決?
$('#11').click(function(){
$('#widget').load('../212/?id=11');
$(this).attr("src", "<?php bloginfo('stylesheet_directory'); ?>/images/category-fantasy-32-disable.png");
});
$('#11').hover(
function () {
//hover event
$(this).attr("src", "<?php bloginfo('stylesheet_directory'); ?>/images/category-fantasy-32-disable.png");
},
function () {
//hover out event
$(this).attr("src", "<?php bloginfo('stylesheet_directory'); ?>/images/category-fantasy-32.png");
});
解決方案是綁定到單擊和懸停兩者。 這是示例代碼
$('p').on('click hover', function () {
alert("Clicked");
});
$('p').hover(
function(){
console.log("X");
},
function(){
console.log("Y");
}
);
這將觸發懸停和懸停方法。 如果您單擊它也可以正常工作。 工作鏈接: http : //jsfiddle.net/43BW4/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.