为什么按钮会导致我的整个网页重新加载? [英] Why does a button cause my whole web page to reload?
问题描述
页面必须以某种方式运行一些代码,可以随时点击一个按钮来重新加载该页面。
我完全失败了,试图找出代码绑定到点击处理程序的位置,所以我想知道是否可以在运行时枚举附加在按钮上的处理程序列表。
更新:阅读下面的答案后,我更改了我的页面中的一行:
< button id =btnSaveAndContinueclass = buttontabindex =290>保存并继续< / button>
到:
< input type ='button'id =btnSaveAndContinueclass =buttontabindex =290value ='保存并继续'/>
这是一个按钮的默认行为。如果要更改它,请执行以下操作:
$(button selector)。click(function(event) {
event.preventDefault();
});
I have a web page I'm working on with jQuery. I'm getting erratic behavior from some elements on my page: Every time a button, any button, on the page is clicked, the page refreshes.
The page must somehow be running some code that reloads that page any time a button is clicked.
I'm completely stumped trying to figure out where the code is getting bound to the click handler, so I would like to know if it is possible to enumerate, at run-time, a list of handlers attached to a button.
Update: After reading the answers given below, I changed a line in my page:
<button id="btnSaveAndContinue" class="button" tabindex="290">Save and Continue</button>
to this:
<input type='button' id="btnSaveAndContinue" class="button" tabindex="290" value='Save and Continue' />
This is the default behaviour of a button. If you want to change it, do something like this:
$("button selector").click( function(event) {
event.preventDefault();
});
这篇关于为什么按钮会导致我的整个网页重新加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!