将按钮添加到 jquery ui 对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4031673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add button to jquery ui dialog
提问by Shahin
I can not add button to this jquery ui dialog. if possible please give me an example . thanks.
我无法向这个 jquery ui 对话框添加按钮。如果可能,请给我一个例子。谢谢。
<script type="text/javascript">
$(document).ready(function () {
//setup new person dialog
$('#dialog2').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: 'auto',
width: '1000',
autoOpen: false,
modal: true,
position: 'top',
draggable: false,
title: "?????? ???????",
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
$('#viewfaktor').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: 'auto',
width: '1000',
autoOpen: false,
modal: true,
position: 'top',
draggable: true,
title: "?????? ???? ???",
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
$('#msgBox').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: 'auto',
width: 'auto',
autoOpen: false,
modal: true,
position: 'center',
draggable: false,
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
});
function showDialog(id) {
$('#' + id).dialog("open");
}
function closeDialog(id) {
$('#' + id).dialog("destroy");
}
</script>
回答by JJS
Sometimes you want to add the buttons dynamically after the dialog is created too. See my answerat the question Add a button to a dialog box dynamically
有时您也想在创建对话框后动态添加按钮。请参阅我对动态向对话框添加按钮的问题的 回答
var mydialog = ... result of jqueryui .dialog()
var buttons = mydialog.dialog("option", "buttons"); // getter
$.extend(buttons, { foo: function () { alert('foo'); } });
mydialog.dialog("option", "buttons", buttons); // setter
回答by Phil.Wheeler
$('#msgBox').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: 'auto',
width: 'auto',
autoOpen: false,
modal: true,
position: 'center',
draggable: false,
open: function (type, data) {
$(this).parent().appendTo("form");
},
buttons: { "OK": function() { $(this).dialog("close"); } }
});
回答by Dale
If you want to add a button to a dialog that is already open you can do something like:
如果要向已打开的对话框添加按钮,可以执行以下操作:
var buttonSet = $('#dialog').parent().find('.ui-dialog-buttonset');
var newButton = $('<button>My New Button</button>');
newButton.button().click(function () {
alert('My new button clicked');
});
buttonSet.append(newButton);
回答by Tim
add this to your function:
将此添加到您的函数中:
buttons: {
OK: function() { //submit
$( this ).dialog( "close" );
},
Cancel: function() { //cancel
$( this ).dialog( "close" );
}
}
So you get
所以你得到
$('#msgBox').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: 'auto',
width: 'auto',
autoOpen: false,
modal: true,
position: 'center',
draggable: false,
buttons: {
OK: function() { //ok
$( this ).dialog( "close" );
},
Cancel: function() { //cancel
$( this ).dialog( "close" );
}
}
open: function (type, data) {
$(this).parent().appendTo("form");
}
});