gpt4 book ai didi

jquery - 单击按钮时停止页面刷新

转载 作者:行者123 更新时间:2023-11-28 04:16:27 25 4
gpt4 key购买 nike

我在页面上有一个按钮,因此每次单击它时都会运行 onclick 代码,然后页面会刷新。早些时候它工作正常,但现在它开始刷新页面。

由于输入类型现在是提交,它会刷新页面,但如果我将输入类型设置为按钮,它不会刷新我的页面,但会刷新我的输入 Bootstrap 验证元素不起作用。

所以我需要我的验证工作以及页面不应该自动刷新。

下面是我的代码。

$("#btn-payment").click(function(){

if($('#select-GenAccount').val() !="" && $('#input-transactionID').val() != "" && $('#select-transactionType').val() != "" && $('#input-transactionDate').val() != "" && $('#input-BankName').val() != "" && $('#input-AccountName').val() != "" && $('#input-Amount').val() != "")
{
if(parseInt($("#input-OutBalance").val()) >= parseInt($("#input-Amount").val()))
{
$("#div-paymentError").css('display','none');
BootstrapDialog.show({
cssClass: 'login-dialog',
title: 'Confirmation',
message: 'Are you sure you want to make a part payment entry?',
buttons: [{
label: 'Yes',
action: function(dialog) {

dialog.close();
GetUserProfileData().done(function(returnedValue)
{
CreateListItemPayment(returnedValue, 'Part_Payment');
}
}, {
label: 'No',
action: function(dialog) {
dialog.close();
}
}]
});
}
else
{
$("#div-paymentError").text("Amount entered can not be more then outstanding balance");
$("#div-paymentError").css('display','inline-block');
}
}
});

按钮的HTML

<input id="btn-payment" class="btn btn-primary" type="submit" value="Submit" style="margin-left: 0px;">

最佳答案

这可能对你有帮助

$("#btn-payment").click(function(e){
e.preventDefault();

//your code goes here.
return false;
})

关于jquery - 单击按钮时停止页面刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48108844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com