我尝试使用JQuery UI Dialog来替换丑陋的javascript:alert()盒子.在我的场景中,我有一个项目列表,并且在每个项目的旁边,我会为每个项目都有一个"删除"按钮.psuedo html设置将是以下内容:
<ul>
<li>ITEM <a href="url/to/remove"> <span>$itemId</span>
<li>ITEM <a href="url/to/remove"><span>$itemId</span>
<li>ITEM <a href="url/to/remove"><span>$itemId</span>
</ul>
<div id="confirmDialog">Are you sure?</div>
Run Code Online (Sandbox Code Playgroud)
在JQ部分,在文档准备好的时候,我首先将div设置为带有必要按钮的模态对话框,然后将那些"a"设置为在删除前触发确认,如:
$("ul li a").click(function() {
// Show the dialog
return false; // to prevent the browser actually following the links!
}
Run Code Online (Sandbox Code Playgroud)
好的,这是问题所在.在初始化时,对话框将不知道谁(项目)将启动它,以及项目ID(!).如何设置这些确认按钮的行为,如果用户仍然选择YES,它将按照链接删除它?
function ValidateField(){
var bAllow= true;
//some checking here
if (bAllow == true && apl.val().trim() == "")
{
showDialog();
showDialog().done(function() {
return true; // wanna return true, but not success
}).fail(function() {
return false; //wanna return false, but not success
});
return false; //stop it to execute to next line
}
return bAllow; //success return }
function showDialog(){
var def = $.Deferred();
var modPop = '<div id="diaCom" title="Information?"><p>something something</p></div>';
$("#diaCom").remove();
$(modPop).appendTo('body');
$("#diaCom").dialog({
resizable: false,
draggable: false,
height:150,
width:300,
modal: true,
buttons: …Run Code Online (Sandbox Code Playgroud)