创建JqueryUI对话框后添加按钮

时间:2013-10-05 04:26:43

标签: jquery jquery-ui

我在创建jquery UI对话框后尝试添加按钮。但以下代码无法正常工作。

我的要求是按钮内容应该以JSON的形式动态传递。所以我正在创建jquery UI对话框并向其添加按钮内容。

下面给出的示例JSON结构。

 "buttons": [{
                        "text": "button1",
                        "functionname": "test12",
                        "fncparam": { "param1": "testparam1", "param2": "1273576235" }
}]

 function dialog_box(dynDiv, rootTemplate) {
            var dialog_buttons = rootTemplate.buttons;
            var dialog = $("#" + dynDiv.id).dialog({
                hide: "explode",
                title: rootTemplate.etype,
                buttons: {},
                text: rootTemplate.text,
                resizable: true,
                minWidth: 200,
                minHeight: 150,
                close: function() {
                    $(dialog).dialog('destroy').remove();
                }
            });

            $('#dialog').dialog('option', 'buttons',
          [
                { text: 'New Button 01', click: function(ev, ui) { alert('New Button 01'); } }
                , { text: 'New Button 02', click: function(ev, ui) { alert('New Button 02'); } }

          ]);


        }

这有什么不对? 在创建Jquery UI对话框后添加按钮的任何其他替代方法?

1 个答案:

答案 0 :(得分:0)

按这样制作按钮

$("#" + dynDiv.id).dialog({
                hide: "explode",
                title: rootTemplate.etype,
                buttons: {},
                text: rootTemplate.text,
                resizable: true,
                minWidth: 200,
                minHeight: 150,
        buttons: [ 
        { text: "Close", 
        click: function() {
         $( this ).dialog( "close" );
         } 
    } ] 
    });
相关问题