这是我的JQuery UI模式窗口的代码:
$('<p>Message</p>').dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
如何传递变量而不是常量字符串(参见上面的Ok
)
答案 0 :(得分:1)
来自jQuery UI dialog button text as a variable
var button_name = 'Test';
var dialog_buttons = {};
dialog_buttons[button_name] = function(){
closeInstanceForm(Function);
}
dialog_buttons['Cancel'] = function(){
$(this).dialog('close');
}
$('#instanceDialog').dialog({
buttons: dialog_buttons
});
答案 1 :(得分:1)
试试这个:
var dynamicButtons= {};
var buttonOne = 'Press Me Please!';
var buttonTwo = 'No way';
dynamicButtons[buttonOne] = function() {
// do your stuffs
};
dynamicButtons[buttonTwo] = function() {
// do your stuffs
};
$('<p>Message</p>').dialog({
modal: true,
buttons: dynamicButtons
});