jQuery ui-模式对话框(创建模式内容的更好方法?) [英] jquery ui - modal dialog (better way to create content of modal?)
本文介绍了jQuery ui-模式对话框(创建模式内容的更好方法?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以在javascript中定义模式内容,而不必总是在页面上有一个元素并从中创建对话框?
Is there a way to define the modal content in the javascript, rather than always having to have an element on the page and create the dialog from that?
它具有标题选项,因此我可以动态"创建模式标题,但是实际内容呢?就像说我需要说的那样,您将要删除图像#539".而不是为每个可能的图像创建模态-甚至从创建元素然后从中创建对话框.
It has the title option, so I can 'dynamically' create a modal title, but what about the actual content? Like say I need it to say, "you are going to delete image #539". Rather than creating a modal for every possible image - or even from creating the element and then making the dialog from that.
必须有一个更好的方法.
There's got to be a better way.
推荐答案
您可以尝试以下方法:
HTML
<button id='diag1'>First dialog</button>
<button id='diag2'>Second dialog</button>
JavaScript
var diag = $('<div id="myDialog" title="Testing!"><span id="dialogMsg"></span></div>');
diag.dialog({
autoOpen: false,
modal: true
});
$('#diag1').click(function() {
$('#dialogMsg').text("Message for dialog 1.");
diag.dialog("open");
});
$('#diag2').click(function() {
$('#dialogMsg').text("Message for dialog 2");
diag.dialog("open");
});
演示此处.
这篇关于jQuery ui-模式对话框(创建模式内容的更好方法?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文