【问题标题】:modal box change title and button names in runtime模态框在运行时更改标题和按钮名称
【发布时间】:2012-07-03 02:15:15
【问题描述】:

我希望能够在运行时更改模式的标题和按钮。 目前我有这个 我有批准或拒绝的操作

var recButton = actions =='approval' ? 'Approve' : 'Deny';

$("#dialog").dialog(
    {
        modal : true,
        buttons : {
            'update all' : function() {
                // window.location.reload();
                // $( this ).dialog( "close" );
                //do something here
            },
            Cancel : function() {
                $(this).dialog("close");
            }
        }
    }); //dialog
});

我也尝试为按钮这样做

$("#dialog").dialog(
    {
        modal : true,
        buttons : {
            recButton : function() { ...

但在模态中它翻译得不好,只是说 recButton 而不是变量值。我也需要更改标题。

更新:通过简单的标题获得标题:

【问题讨论】:

  • 你总是这样缩进代码吗?
  • 是的..很糟糕吗?我有很多代码

标签: javascript jquery jquery-ui modal-dialog jquery-dialog


【解决方案1】:

嘿 Autolycus:试试这个人:工作演示 http://jsfiddle.net/C4A9b/10/

请使用firebug检查元素id/类:

$('.ui-dialog-title').html("HULK is awesome"); 应该可以解决问题。

希望对:)有帮助

代码

$(document).ready(function() {
    $('#theLink').click(function(){
                $( "#forgot-dialog" ).dialog( "open" );    
    });

    $( "#forgot-dialog" ).dialog({
            modal: true,
            autoOpen: false,
            height: 255,
            width: 300,
            buttons: {
                "ChangeTitle": function() {

                    alert("Title before cahnge ==> " + $('.ui-dialog-title').html());
                   $('.ui-dialog-title').html("HULK is awesome");
                    // document.forms["forgotform"].submit();
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            },
    });


});

var formname = "form_name_here";

$("#ui-dialog-title-"+formname).innerHTML = "Hulk is awesome title";

下图显示之前和之后。

点击更改标题按钮前的图片

点击更改标题后

【讨论】:

  • 在您发布此答案之前,我已经更改了标题并更新了票证。我希望按钮文本动态变化
  • 嗨 @Autolycus 试试这个 bruv:jsfiddle.net/naaT8/1 当你点击按钮 changetitle 它会改变按钮的标题和文本,这应该会有所帮助。 :)
猜你喜欢
  • 2015-04-05
  • 1970-01-01
  • 1970-01-01
  • 2013-10-03
  • 2016-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-22
相关资源
最近更新 更多