问题描述
我使用的引擎会调用jquery tabs.js脚本来处理tab函数。问题是,只要标签在页面的顶部,并且您点击链接,它们会快速向下滚动到页面底部。我一直在努力解决这个问题几个小时,所有的解决方案指向类似的答案,但没有为我工作。
The engine I use calls the jquery tabs.js script to handle the tab functions. Problem is that anytime the tabs are at the top of the page and you click on a link, they quickly scroll back down towards the bottom of the page. I've been trying to solve this problem for hours and all solutions point to similar answers, but none work for me.
$.fn.tabs = function() {
var selector = this;
this.each(function() {
var obj = $(this);
$(obj.attr('href')).hide();
$(obj).click(function() {
$(selector).removeClass('selected');
$(selector).each(function(i, element) {
$($(element).attr('href')).hide();
});
$(this).addClass('selected');
$($(this).attr('href')).fadeIn();
return false;
e.preventDefault();
});
});
$(this).show();
$(this).first().click();
};
根据我发现的一个建议,我将上面的一行改为:
As per a suggested fix I found, I changed one of the lines above to read:
$($(element).attr('href')).fadeOut(1);
我也尝试过添加 e.preventDefault(); return false;但还是没有运气?我找到了一个运行的和问题不存在那里。我一直在使用火狐浏览器并检查代码来尝试找到它们如何做,但在打墙后几个小时我寻求你的智慧哦聪明的人!
I've also tried to add e.preventDefault(); after return false; but still no luck?!? I was able to find a site that runs a different template and the problem doesn't exist there. I've been using Firefox and examining the code to try and find how they do it but after hours of hitting the wall I seek your wisdom oh wise ones!
推荐答案
在html中,只需添加 onclick =return false;
,跳转将停止,例如:
In the html, just add onclick="return false;"
and the jumping will stop, eg:
<ul>
<li><a href="#tabsDetails" id="tabsDetailsLink" onclick="return false;" >Details</a></li>
<li><a href="#tabsAddress" id="tabsAddressLink" onclick="return false;" >Address</a></li>
</ul>
这篇关于停止jquery TABS从跳跃/向上滚动时点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!