开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜