jQuery UI对话框按钮文本作为变量

问题描述:

谁能告诉我如何在jQuery UI对话框中为按钮文本使用变量? 我想创建一个动态按钮名称.

Can anyone tell me how can i use a variable for button text in jQuery UI dialog? I want to make a dynamic button name.

由于jQuery处理按钮名称的方式(可以带引号或不带引号),因此无法使用

This won't work because of the way jQuery handles the button name (can be with or without quotes)

这将起作用:

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 });