弹出 jQuery UI 对话框时,如何防止滚动到页面顶部? [英] How do I prevent scrolling to the top of a page when popping up a jQuery UI Dialog?

查看:29
本文介绍了弹出 jQuery UI 对话框时,如何防止滚动到页面顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 jTemplates 在客户端创建一个相当大的表,每一行都有一个按钮可以打开一个 jQuery UI 对话框.但是,当我向下滚动页面并单击其中一个按钮时,jQuery 对话框将打开,但滚动位置丢失并且页面跳回到顶部(阻塞和实际对话框显示在屏幕上).有没有人看到或知道可能导致此问题的原因?

I currently use jTemplates to create a rather large table on the client, each row has a button that will open a jQuery UI dialog. However, when I scroll down the page and click on one of those buttons, jQuery dialog will open, but the scroll position get lost and the page jumps back to the top (with the blocking and the actual dialog showing off the screen). Has anyone seen or know what might cause this problem?

谢谢.

推荐答案

您是否使用锚标记来实现弹出对话框的按钮"?如果是这样,您将希望打开对话框的单击处理程序返回 false,以便不调用锚标记的默认操作.如果您使用的是按钮,您还需要确保它不会提交(通过从处理程序返回 false)并完全刷新页面.

Are you using an anchor tag to implement the "button" that pops the dialog? If so, you'll want the click handler that opens the dialog to return false so that the default action of the anchor tag isn't invoked. If you are using a button, you'd also need to make sure that it doesn't submit (by returning false from the handler) and completely refresh the page.

例如

$('a.closeButton').click( function() {
     $('#dialog').dialog('open');
     return false;
});


<a class='closeButton'>Close</a>

这篇关于弹出 jQuery UI 对话框时,如何防止滚动到页面顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆