2012-06-11 78 views
1

如何禁用链接,当点击这个代码时,我为图像淡出使用hoverintent。我现在使用的是一个已命名的锚,但它跳转,所以我想禁用点击。禁用点击#与hoverintent的链接

<A class="next2 nextbuttonB" href="#top">INSTALL</A> 
<A class="next2 nextbuttonA" href="#top">ESTIMATE</A> 

和jQuery的

$('#A,#B,').addClass('nextHide'); 

$('.nextbuttonA').hoverIntent(function() { 
$('#A').fadeIn("slow");$('#B').fadeOut(); 
}, function() { 
$('#B').hide(); 
}); 

$('.nextbuttonB').hoverIntent(function() { 
$('#B').fadeIn("slow");$('#A').fadeOut(); 
}, function() { 
$('#A').hide(); 
});  

$('.nextbutton').hoverIntent(function() { 
$('#A,#B').fadeOut(); 
}, function() { 
$('#A,#B').hide(); 
}); 

$('#A,#B').mouseleave(function(){ 
    $('#A,#B').fadeOut(); 
}); 
+0

'event.preventDefault()'或'返回FALSE'将解决这个问题。 – undefined

回答

2

要么做一个

return false;

或传递事件作为efunction,做一个e.preventDefault()这样的:

$('.next2').click(
    function(e){ 
     e.preventDefault(); //return false; //would also work 
     //then do other stuff 
}); 

另外,为什么使用#top?如果你不希望它像一个命名的锚点?你可以只使用:

<a href="javascript:void(0)">...</a>

+0

仅仅使用..也不会跳。 – vendettamit

+0

您需要使用哈希标记链接进行悬停,并将哈希标记作为链接移至文档顶部,以便命名锚点至少可以更靠近它。 jsvoid和preventDefault杀死链接上的悬停样式。 – Gord

2

试试这个 改变/根据需要添加选择

$("#A,#B").click(function(event) { 
    event.preventDefault(); 
}); 
+0

也停止了悬停样式。所以你点击它改变颜色的链接,但不会变回... – Gord