如何在jquery对话框中将对话框按钮名称作为变量传递

时间:2014-12-02 10:35:34

标签: jquery jquery-ui jquery-ui-dialog

这里我希望对话框按钮值为'yes','no'作为变量。我想将变量butt1传递给按钮。

 var button ='Yes'
 $("#modal_confirm_yes_no").dialog({
        bgiframe: true,
        autoOpen: false,
        minHeight: 200,
        width: 350,
        modal: true,
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        buttons: {
                'Yes': function(){
                    $(this).dialog('close');
                    callback(true);
                },
                'No': function(){
                    $(this).dialog('close');
                    callback(false);
                }
            }
    });

1 个答案:

答案 0 :(得分:3)

 var button ='Yes'
 $("#modal_confirm_yes_no").dialog({
    bgiframe: true,
    autoOpen: false,
    minHeight: 200,
    width: 350,
    modal: true,
    closeOnEscape: false,
    draggable: false,
    resizable: false,
    buttons: [
        {text: button, click: function() {
            $(this).dialog('close');
            callback(true);
        }},
        {text: 'No', click: function() {
            $(this).dialog('close');
            callback(false);
        }}
    ]
});