0
當我提交併單擊確定它繼續,但當我按「取消」它仍然提交。我試過使用這段代碼,但提交和取消按鈕仍然執行相同的操作。javascript確認(取消)仍然提交表單時返回false
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>
「
與這個問題無關,但是你的__never__在JS的if中需要'== true'。只要使用:'if(r){'並替換'} else if(r == false){'with'} else {' – Cerbrus
你確定r是false? 可以顯示確認功能嗎? –