2

打开 jQueryUI 对话框后,我想执行一个 GET 请求,并根据响应更改按钮文本。经过几个小时的努力,我终于得到了以下工作。这真的是最好的/唯一的吗?谢谢

$("#dialog").dialog({
    open        : function() {
        var dialog=$(this);
        $.get('ajax.php', function (data) {
            var buttons=dialog.dialog( "option", "buttons" );
            buttons[1].text=(data==1)?"CANCEL":"CLOSE";
            var buttons=dialog.dialog( "option", "buttons" ,buttons);
        });
    },
    buttons     : [
        {
            text    : 'SAVE',
            click    : function() {}
        },
        {
            text    : 'CANCEL',
            click    : function() {}
        }
    ]    
});
4

1 回答 1

2

您可以像这样更改按钮文本...

下面给出的是没有ajax

function setbutton(button1, button2) {
var btns = {};
btns[button1] = function() {
    //your function
   $( this ).dialog( "close" );
};
btns[button2] = function() {
    // Do nothing
    //your function
    $( this ).dialog( "close" );
};

document.getElementById('dialogshow').innerHTML = "<div>open with given button text</div>";


$( "#dialogshow" ).dialog({
    autoOpen: true,
    width: 450,
    height: 200,
    modal: true,
    position: 'center',
    modal: true,
    buttons: btns
});
}
$('.test').click(function() {
setbutton('start', 'End');//in here button name you want..
});

观看现场演示

于 2012-11-29T13:45:49.277 回答