admin管理员组

文章数量:1335600

I want to be able to change the title of my modal and the buttons on run time. currently I have this I have actions either approval or Deny

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
});

I also tried to do this for button

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

but in modal it didn't translate well and just said recButton instead of the variable value. Also I need to change title too.

Update: got title working by simply title:

I want to be able to change the title of my modal and the buttons on run time. currently I have this I have actions either approval or Deny

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
});

I also tried to do this for button

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

but in modal it didn't translate well and just said recButton instead of the variable value. Also I need to change title too.

Update: got title working by simply title:

Share Improve this question edited Sep 23, 2014 at 17:28 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Jul 3, 2012 at 2:15 Asim ZaidiAsim Zaidi 28.4k49 gold badges138 silver badges224 bronze badges 2
  • 1 do you always indent the codes in that way? – Ram Commented Jul 3, 2012 at 2:17
  • yes ..is it bad? I have a lot of code – Asim Zaidi Commented Jul 3, 2012 at 2:18
Add a ment  | 

1 Answer 1

Reset to default 6

Hey Autolycus: try this man: working demo http://jsfiddle/C4A9b/10/

Please use firebug to check the element id / class:

$('.ui-dialog-title').html("HULK is awesome"); should do the trick.

Hope it helps :)

code

$(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" );
                }
            },
    });


});

OR

var formname = "form_name_here";

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

Below Image show before and After.

Image before clicking changetitle button

After clicking change title

本文标签: javascriptmodal box change title and button names in runtimeStack Overflow