打开jquery对话框时,页面自动转到顶部

dom*_*lao 2 jquery

每次我点击底部的按钮打开jquery对话框时,页面都会自动滚动到顶部.我正在使用firefox浏览器.

请指教.

非常感谢.

Tal*_*han 5

我想你必须阻止按钮的默认操作

$('#myButton').click(function(event){
    event.preventDefault()
    // .... open dialog.
});
Run Code Online (Sandbox Code Playgroud)

或者你必须在按钮的onclick事件上返回false

<input type="button" value="My Button" onclick="openDialog();return false;" />
Run Code Online (Sandbox Code Playgroud)