jQuery UI:仅使用jQuery创建对话框
我有以下代码:jQuery UI:仅使用jQuery创建对话框,jquery,jquery-ui-dialog,Jquery,Jquery Ui Dialog,我有以下代码: <div id="leaving-dialog" title="Confirmation Required"> <p>You are now leaving the ****** section of ******</p> </div> jQuery(document).ready(function ($) { $("#leaving-dialog").dialog({ au
<div id="leaving-dialog" title="Confirmation Required">
<p>You are now leaving the ****** section of ******</p>
</div>
jQuery(document).ready(function ($)
{
$("#leaving-dialog").dialog({
autoOpen: false,
modal: true,
width: 480,
height: 240,
resizable: false,
draggable: false,
zIndex: 9999999999
});
$(".leaving-section").click(function (event) {
event.preventDefault();
var targetUrl = $(this).attr("href");
$("#leaving-dialog").dialog({
buttons: {
"No, I want to stay here": function () {
$(this).dialog("close");
},
"Yes, that's okay": function () {
//window.location.href = targetUrl;
window.open(targetUrl);
$(this).dialog("close");
}
}
});
$("#leaving-dialog").dialog("open");
});
});
您现在将离开的*******部分******
jQuery(文档).ready(函数($)
{
$(“#离开对话框”).dialog({
自动打开:错误,
莫代尔:是的,
宽度:480,
身高:240,
可调整大小:false,
可拖动:错误,
zIndex:9999999
});
$(“.leaving section”)。单击(函数(事件){
event.preventDefault();
var targetUrl=$(this.attr(“href”);
$(“#离开对话框”).dialog({
按钮:{
“不,我想留在这里”:函数(){
$(此).dialog(“关闭”);
},
“是的,没关系”:函数(){
//window.location.href=targetUrl;
打开(targetUrl);
$(此).dialog(“关闭”);
}
}
});
$(“离开对话框”)。对话框(“打开”);
});
});
我想做的是将HTML移动到jQuery代码中,这样它就可以在DOM中纯客户端创建。也许将其存储在变量中
谢谢$(函数(){
var dialog='您现在要离开*********的**********部分;
$('body')。追加(对话框);
$(“#离开对话框”).dialog({…});
});
删除
<div id="leaving-dialog" title="Confirmation Required">
<p>You are now leaving the ****** section of ******</p>
</div>
您现在将离开的*******部分******
并将其添加到函数调用中
jQuery(document).ready(function ($)
{
$('body').append('<div id="leaving-dialog" title="Confirmation Required"><p>You are now leaving the ****** section of ******</p></div>');
[...]
});
jQuery(文档).ready(函数($)
{
$('body').append('p>您现在离开*********'的*******部分);
[...]
});
您可以将原始html附加到任何文档中,如下所示:
$('<div id="leaving-dialog" title="Confirmation Required"> <p>You are now leaving the ****** section of ******</p></div>').appendTo('body');
$('您现在离开******'的*******部分)。appendTo('body');
资料来源:
$('<div id="leaving-dialog" title="Confirmation Required"> <p>You are now leaving the ****** section of ******</p></div>').appendTo('body');