如何在按钮单击jquery上停止页面重新加载 [英] How to stop page reload on button click jquery
本文介绍了如何在按钮单击jquery上停止页面重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码使用jQuery进行按钮点击事件。单击按钮时,页面将重新加载。
I am using this below code for button click event using jQuery. When button is clicked the page reloads.
$('#button1').click(function () {
//Code goes here
return false;
});
推荐答案
如果你的按钮是 button
元素,确保明确设置类型
属性,否则WebForm会默认将其视为提交。
If your "button" is a button
element, make sure you explicity set the type
attribute, otherwise the WebForm will treat it as submit by default.
<button id="button1" type="button">Go</button>
如果是输入
元素,请执行此操作使用以下jQuery:
If it's an input
element, do so with jQuery with the following:
$('#button1').click(function(e){
e.preventDefault();
// Code goes here
});
了解更多: event.preventDefault()
这篇关于如何在按钮单击jquery上停止页面重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文