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