Jquery - .click() 不滚动页面
我将在 jQuery 上创建一个如下所示的函数:
$(document).ready(function() {
$('#header_rules').click(function() {
// here i define myFunction()
});
});
<a id="header_rules" href="#">RULES</a>
而不是
<a id="header_rules" href="#" onClick="myFunction();return false">RULES</a>
But I don't know how to防止在有人单击链接后使用 jQuery 滚动到页面顶部。
事实上,我将完全摆脱原生 JS,这可能会产生一些麻烦(这就是我使用 jQuery 等 JS 框架的原因)。
有什么帮助吗?干杯
I'm about to make a function on jQuery like this:
$(document).ready(function() {
$('#header_rules').click(function() {
// here i define myFunction()
});
});
<a id="header_rules" href="#">RULES</a>
instead of
<a id="header_rules" href="#" onClick="myFunction();return false">RULES</a>
But I don't know how to prevent scrolling to the top of the page using jQuery after someone clicks the link.
In fact, I'll total get rid about native JS, which could yield some trouble (that's why I use a JS framework like jQuery).
Any help? Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
调用
e.preventDefault();
,其中e
是点击处理程序的第一个参数:Call
e.preventDefault();
wheree
is the first argument of your click handler: