开发者

How set the names of jquery-ui buttons on dialog window from variable?

开发者 https://www.devze.com 2023-03-12 21:18 出处:网络
jquery-ui dialog window in javascript: $( \"#dialog-confirm\" ).dialog({ resizable: false, height:140, modal: true,

jquery-ui dialog window in javascript:

$( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Ok": function() {
                    $( this ).dialog( "close" );
                },
                "Cancel": f开发者_如何学运维unction() {
                    $( this ).dialog( "close" );
                }
            }
        });

There two buttons "Ok" and "Cancel". On each button there function. Buttons names fastened hardly. There some ways to named buttons from variable?? like this:

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

I try code above but buttons appear with names "Button1" and "Button2". Can I also display images in buttons but not text???


Referring to http://jqueryui.com/demos/dialog/ you can see there are 2 alternate ways of defining the buttons, one is what you are using here, the second is using arrays.

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

It looks like this must solve your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消