gpt4 book ai didi

javascript确认(取消)返回false时仍然提交表单

转载 作者:行者123 更新时间:2023-11-28 18:59:05 27 4
gpt4 key购买 nike

当我提交并单击“确定”时,它会继续,但当我按“取消”时,它仍然会提交。我尝试使用此代码,但提交和取消按钮仍然执行相同的操作。

model.saveForm = function() {
var r = confirm("Press a button");
alert(p);
if (r == true) {
x = "You pressed OK!";

if (!validateRequiredNew()) return;
model.saving(true);

// check if group id is needed
var generatedGroupIdPromise = null;
// if (model.selectedUsers().length > 1 || model.selectedUsers()[0].selectedRoles().length > 1) {
generatedGroupIdPromise = $.ajax({
url: '../_vti_bin/listdata.svc/GroupIdGeneratorList',
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{Title: 'dummy'}",
processData: false,
dataType: "json"
});

} else if (r == false){
x = "You pressed Cancel!";
}

和 aspx 页面:

<button data-bind="click: saveForm, visible: !saving()">Submit Request</button>

最佳答案

只需将 return false;event.preventDefault(); 放入您的方法中。

关于javascript确认(取消)返回false时仍然提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32988915/

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