【问题标题】:How set the names of jquery-ui buttons on dialog window from variable?如何从变量设置对话框窗口上 jquery-ui 按钮的名称?
【发布时间】:2017-09-18 14:43:19
【问题描述】:

javascript中的jquery-ui对话框窗口:

$( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Ok": function() {
                    $( this ).dialog( "close" );
                },
                "Cancel": function() {
                    $( this ).dialog( "close" );
                }
            }
        });

有两个按钮“确定”和“取消”。每个按钮都有功能。按钮名称几乎没有固定。有一些方法可以从变量中命名按钮?像这样:

var Button1 = "Ok";
var Button2 = "Cancel";
$( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                Button1: function() {
                    $( this ).dialog( "close" );
                },
                Button2: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

我尝试了上面的代码,但按钮出现的名称为“Button1”和“Button2”。 我也可以在按钮中显示图像而不是文本吗???

【问题讨论】:

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


    【解决方案1】:

    参考http://jqueryui.com/demos/dialog/你可以看到有两种定义按钮的方法,一种是你在这里使用的,第二种是使用数组。

    var button1 = 'Ok';
    var button2 = 'Not Ok';    
    $( ".selector" ).dialog({ buttons: [
        {
            text: button1,
            click: function() { $(this).dialog("close"); }
        },
        {
            text: button2,
            click: function() { $(this).dialog('close'); }
        }
    ] });
    

    看来这一定能解决你的问题。

    【讨论】:

    • 我也可以从变量中设置javascript中对话窗口的标题栏名称吗?不在标签中设置 title=""。
    • @darien-fawkes 您可以从传递给对话框的选项中的变量中设置标题。
    • 这对我不起作用,我认为是因为我使用的是旧版本的 jQuery UI (1.7.2)。这是对我有用的解决方案:stackoverflow.com/questions/1357281/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 2011-04-08
    • 2016-04-02
    相关资源
    最近更新 更多