问题描述
我目前使用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对话框时,如何防止滚动到页面顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!