简体   繁体   English

页面不应该在“更多”按钮单击时返回到顶部

[英]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.

相关问题 Android单击该按钮可以转到另一个页面? - Android click on the button to go to another page? 单击提交按钮时,JScrollPane会在首页上滚动 - JScrollPane scroll on the top page when the submit button click 在单击按钮值应该进入jsp页面为空 - on click the button value should get in jsp page is null 当点击“提交”按钮时,它应该重定向到 Android Studio 的主页 - when click on “Submit” Button it should redirect to home page in Android Studio 在页面完全加载后计算页面中特定元素的总数(应该没有特定的加载更多按钮) - calculate total number of particular element of a page after the page is fully loaded (there should be no specific load more button) 后退按钮转到上一页 - Back button to go to previous page 按钮单击onListener并转到不同的xml布局 - button click onListener and go to different xml layout Android-单击按钮进入新屏幕 - Android - Go to new screen on button click 点击按钮的上半部分 - 不起作用? - Click on the top half of a button - doesn't work? 在Selenium Web驱动程序中,我可以单击“保存”按钮,然后保存页面,但是它没有显示此类元素错误消息,无法继续 - In selenium web driver,I can able to click the save button then page getting saved but it shows no such element error message not able to go futher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM