2

たとえば、jqueryui、このコードのダイアログプラグインを使用します。

$( "#showUser-form" ).dialog(
                    {
                        buttons: {
                            "OK": function()
                            {
                                    $( this ).dialog( "close" );
                            },
                            cancel: function()
                            {
                                $( this ).dialog( "close" );
                            }
                        },
                        close: function() {}
                    });

たとえば多言語のウェブサイトのボタン「キャンセル」のテキストを変更できるようにするにはどうすればよいですか?

よろしく

ヒューゴ

4

1 に答える 1

3

ボタンを含む新しいオブジェクトを作成し、それをbuttonsパラメーターに渡す必要があります。次に、ボタンのテキストを動的に設定できます。

jsFiddleはこちら

このような:

//You can dynamically change button text here
var buttons = [,];
buttons['OK'] = 'OK :)';
buttons['Cancel'] = 'Cancel :(';

var buttonArray = {};
buttonArray[buttons['OK']] = function() {
    //Set OK function here
    $(this).dialog('close');
};
buttonArray[buttons['Cancel']] = function() {
    //Set Cancel function here
    $(this).dialog('close');
};


$(function () {
    $('#dialog').dialog({
        buttons: buttonArray
    });
});
于 2012-10-26T14:47:02.437 に答える