简体   繁体   English

为什么按钮会导致我的整个网页重新加载?

[英]Why does a button cause my whole web page to reload?

I have a web page I'm working on with jQuery. 我有一个我正在研究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. 我完全难以找到代码绑定到click处理程序的位置,所以我想知道是否可以在运行时枚举附加到按钮的处理程序列表。

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();
});

You have to stop the default behavior for the event with event.preventDefault() within your click handler. 您必须在click处理程序中使用event.preventDefault()停止事件的默认行为。

See this 看到这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM