- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有四个链接,href 指向通过 .load()
加载的页面的 URL,问题是在 IE 中,当你点击它时页面跳转,我附上了一个 (window).scrollTo(0)
到代码中,并在除 IE 之外的所有浏览器中修复它。
我还在代码上设置了return false
,因此它停止了默认行为。
我看过:Page jumps to the top onclick并尝试实现答案,但它似乎对我不起作用。
有人知道解决办法吗?
href 的:
<a href="welcome.html" name="welcome">Welcome</a>
<a href="about.html" name="about">About</a>
<a href="forum.html" name="forum">Forum</a>
<a href="contact.html" name="contact">Contact</a>
jQuery 代码:
$('#jqNav li a').click(function(e){
if($(this).parent().is(".nav1")){ $('.landing .main .nav ul').css({ "background-position" : "0 -50px" });}
else if($(this).parent().is(".nav2")) { $('.landing .main .nav ul').css({ "background-position" : "0 -100px" });}
else if($(this).parent().is(".nav3")) { $('.landing .main .nav ul').css({ "background-position" : "0 -150px" });}
else if($(this).parent().is(".nav4")) { $('.landing .main .nav ul').css({ "background-position" : "0 -200px" });};
stopAnim = true;
$page = $(this).attr('href');
var $hashTag = $(this).attr('name');
window.location.hash = $hashTag;
loadData();
$(window).scrollTop(0);
e.preventDefault();
});
最佳答案
回答我自己的问题;
发生的事情是 window.location.hash
是从 <a name="hash name">
生成的所以浏览器将页面推送到页面上的我的元素。
我所做的是从 anchor 标记中删除名称元素,并通过 jQuery 推送名称。因为我只有 4 个 anchor 标签,所以它是我的场景最简单的解决方案,但是如果你引用了很多散列标签并希望阻止它跳转,我在 Stack Overflow 上找到了另一篇帖子,其中有一些很好的答案。
关于jquery - 在 IE 中点击 <a href> 标签跳转,jquery 附加到 a href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458462/
menu Home Events Technical Schedule
我试图阻止触发默认 anchor 链接和 onclick 事件。 这是 HTML 代码: Google 我正在尝试使用以下 jQuery 代码阻止任何重定向的发生: $("#mylink").cli
我想在单击父 div 上的任意位置时切换我的 div,除非单击 anchor 元素。因此,例如,如果我单击示例中的第一个文本,我希望它切换,但在我的示例中的第二个文本上,我不希望它切换。 JSFidd
我在通过 jQuery 伪造 anchor 点击时遇到问题:为什么我的thickbox在我第一次点击输入按钮时出现,但第二次或第三次却没有出现? 这是我的代码: Link 当我直接点击链接时,它总是
我已经从 Mootools 切换到 jQuery,因为我认为它有更好的支持。我有这样的 HTML: Opcje Opcje Opcje Opcje Opcje Opcje Opcje JS
我是一名优秀的程序员,十分优秀!