这是我的JQuery UI模式窗口的代码:

$('<p>Message</p>').dialog({
    modal: true,
    buttons: {
      Ok: function() {
         $( this ).dialog( "close" );
      }
    }
});


如何传递变量而不是常量字符串(请参见上面的Ok

最佳答案

尝试这个:

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


演示:http://jsbin.com/omawu4/2/

10-02 15:24