如何在jQuery UI确认对话框中更改按钮标签

san*_*nta 2 jquery jquery-ui

我想使用jQuery的UI对话框进行确认:

$( "#dialog-confirm" ).dialog({
        buttons: {
            "Button One": function() {
                $( this ).dialog( "close" );
            },
            "Button Two": function() {
                $( this ).dialog( "close" );
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

但我想根据条件更改按钮标签:

if (status == "active") {
    var b1 = "Red";
    var b2 = "Green";
} else {
    var b1 = "Green";
    var b2 = "Red";
}
Run Code Online (Sandbox Code Playgroud)

似乎无法将两者结合起来......

and*_*dyb 5

通过提供新的按钮数组,您可以在创建jQuery UI对话框后设置按钮.

如果你改变了status从开变量任何active本演示中,你可以看到按键得到带有不同标签的创建.