[英]Page should not go to the top on “more” button click
I have a JSP page which has JQuery mobile implementation, on the page load 8 products are shown and a "MORE" button it provided at the bottom, on click of the "MORE" button 8 more products will be populated, but when I click on "MORE" button 8 new products are loaded and the page goes to the top which is not correct. 我有一个JSP页面,其中有JQuery移动实现,在页面上显示8个产品,并在底部提供“MORE”按钮,点击“MORE”按钮8将会填充更多产品,但是当我点击在“更多”按钮上加载8个新产品,页面转到顶部,这是不正确的。 So, how can I prevent the page to go back to the top?
那么,我怎样才能阻止页面返回顶部?
I'd assume your jQuery click handler looks something like this: 我假设你的jQuery点击处理程序看起来像这样:
$('.more').click(function(e) {
loadMore();
// ...
});
By default the click event will still bubble up to the browser, and perform its default event: following the link href (#). 默认情况下,click事件仍会冒泡到浏览器,并执行其默认事件:在链接href(#)之后。
To prevent this, change your code to: 要防止这种情况,请将代码更改为:
$('.more').click(function(e) {
e.preventDefault();
loadMore();
// ...
});
http://api.jquery.com/event.preventDefault/ http://api.jquery.com/event.preventDefault/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.