如何在函数中创建jQuery对话框 [英] How to create jQuery Dialog in function
问题描述
有人知道如何在函数中创建jQuery对话框吗?我找不到设置消息的属性...在我发现的每个示例中,对话框均已静态写入div标签中的代码中.但是,我想以动态方式创建它,所以我需要知道如何在函数中创建对话框.
Does anyone know how to create a jQuery Dialog in a function? I can't find an attribute to set the message... In every example I found, the dialog has been statically written into the code in a div-tag. However, I want to create it dinamically, so I need to know how to create a dialog in a function.
设置标题没问题:
<script>
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;
$(function() {
$( "#dialog" ).dialog({
autoOpen: false,
show: "blind",
hide: "explode"
});
$( "#opener" ).click(function() {
//$( "#dialog" ).dialog( "open" );
$( this ).dialog({ title: 'Please confirm deletion!' });
return false;
});
});
</script>
</head>
<body>
我有文档和一些示例,此处.
I have the documentation and some examples here.
感谢大家的帮助.
干杯, o
============================ [解决方案] ================ =====================
============================= [SOLUTION]=====================================
感谢所有回答此问题的人.这就是我想要的:
Thanks for all who answered this questions. This is how i wanted it:
function createDialog(title, text) {
return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
.dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Confirm": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
}
例如可以这样调用它(单击图像):
And it can be called for example like this (clicking on an image):
<img src="delete.png" onClick="createDialog('Confirm deletion!', 'Do you really want to delete this package?')">
推荐答案
function createDialog(title, text, options) {
return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
.dialog(options);
}
这篇关于如何在函数中创建jQuery对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!