如何在按钮单击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()