jQuery 打开后更改 jqueryUI 对话框按钮中的文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13618349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:48:25  来源:igfitidea点击:

Changing text within jqueryUI dialog button after it is open

jqueryjquery-uijquery-ui-dialog

提问by user1032531

How can I change the text for the cancel button from CANCEL to CLOSE? Thanks!

如何将取消按钮的文本从 CANCEL 更改为 CLOSE?谢谢!

$("#dialog").dialog({
    buttons     : [
        {
            text    : 'SAVE',
            click    : function() {}
        },
        {
            text    : 'CANCEL',
            click    : function() {}
        }
    ]    
});
$("#button").click(function(){alert('Please change cancel button text from "CANCEL" to "CLOSE"');});

<div id="dialog"><button id="button">Change cancel button text from "CANCEL" to "CLOSE"</button></div>

回答by mattn

Specify class name to your dialog, and select UI buttons from the class.

为对话框指定类名,然后从类中选择 UI 按钮。

$('#foo').dialog({
    buttons: {
        CANCEL: function() {
            alert(1);
        }
    },
    dialogClass: 'my-dialog'
});
$('.my-dialog .ui-button-text:contains(CANCEL)').text('CLOSE');

回答by Олег Всильдеревьев

It is a really simple thing :)

这是一件非常简单的事情:)

$( "#dialog" ).dialog( {
    "buttons" : [
    {
        id: "my-button",
        text: "My button",
        click:function() {
            $("#my-button span").text( "Our button!:)" );
        }
    } ]
} );

回答by greener

You can set the text of the button outside the initialization (documentation):

您可以在初始化(文档)之外设置按钮的文本:

$( "#dialog" ).dialog({
    autoOpen: true,
    buttons: [{
        text: "Cancel",
        click: function() {
            $( this ).dialog( "close" );
        }
    }]
});
$( "#dialog" ).dialog( "option", "buttons", [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ] );

You can also bind it to an event.

您也可以将其绑定到事件。