为什么按钮会导致我的整个网页重新加载? [英] Why does a button cause my whole web page to reload?

查看:129
本文介绍了为什么按钮会导致我的整个网页重新加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我正在使用jQuery的网页。我的页面上的某些元素出现不规则的行为:每次点击页面上的按钮,页面都会被刷新。



页面必须以某种方式运行一些代码,可以随时点击一个按钮来重新加载该页面。



我完全失败了,试图找出代码绑定到点击处理程序的位置,所以我想知道是否可以在运行时枚举附加在按钮上的处理程序列表。



更新:阅读下面的答案后,我更改了我的页面中的一行:

 < 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屋!

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