禁用使用hoverintent单击#link

时间:2012-06-11 05:44:24

标签: jquery 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();
});

2 个答案:

答案 0 :(得分:2)

要么做一个

return false;

或将e作为function传递给您的e.preventDefault(),并执行$('.next2').click( function(e){ e.preventDefault(); //return false; //would also work //then do other stuff }); ,如下所示:

#top

另外,为什么要使用<a href="javascript:void(0)">...</a>?如果你不希望它表现得像命名锚?你可以使用:

{{1}}

答案 1 :(得分:2)

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

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