[英]creating confirm dialog in jquery
$("#first").dialog({ width: 304, modal: true,
beforeclose: function (e, ui)
{
$("#confirm").dialog({ width: 500, modal: true,
buttons: {
"Confirm": function () {
document.location.href = "/Home/Index";
},
"Cancel": function () {
$(this).dialog('close');
return false;
}
}
});
}
});
#first
對話框關閉,無需等待#confirm
對話框打開。 我知道javascript的confirm()
函數,但我想在這種情況下使用對話框。 我怎樣才能做到這一點?
從精細手冊 :
beforeClose(event,ui)
對話框即將關閉時觸發。 如果取消,對話框將不會關閉。
所以你希望你的beforeClose
處理程序return false
以防止對話框關閉:
beforeClose: function(e, ui) {
$("#confirm").dialog({ width: 500, modal: true, /* ... */ });
return false;
}
您的“ 確認”按鈕會更改位置,因此您不必擔心beforeClose
處理程序會阻止第二個對話框關閉第一個對話框。 如果你沒有改變頁面位置,那么你需要一些類型的標志來保持beforeClose
防止所有關閉; 像這樣的東西,例如:
beforeclose: function(e, ui) {
var $dlg = $(this);
if($dlg.data('can-close')) {
$dlg.removeData('can-close');
return true;
}
$("#confirm").dialog({
//...
buttons: {
Confirm: function() {
$(this).dialog('close');
$dlg.data('can-close', true);
$dlg.dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
return false;
}
我將回答我自己的問題,這很好:
$("#first").dialog({ width: 304, modal: true,
beforeclose: function (e, ui)
{
$("#confirm").dialog({ width: 500, modal: true,
buttons: {
"Confirm": function () {
document.location.href = "/Home/Index";
},
"Cancel": function () {
$(this).dialog('close');
}
}
});
return false;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.