开发者

Trigger a button click inside a jQuery UI Dialog

it is a very simple question that I'm not finding an answer for it. I have a dialog and in some events happening inside the dialog I want to click one of the dialog buttons. The code which defines the dialog is:

var dialog = $('<div>').dialog({
    autoOpen: false,
    title : title,
    resizable : false,
    buttons : {
        'CANCEL' : {
            text : messages.Cancel,
            click : function(){$(this).dialog('close')}
        },
        'OK' : {
 开发者_运维问答           text : messages.Ok,
            click : okButtonCallback
        }
    }
});

and in my event I can get the dialog, find the buttons but I can not trigger the click event with right reference passed as this. I do this:

buttons = dialog.dialog('option', 'buttons');

and I have the buttons each of them has the click function. If called directly or through trigger('click'), they call the click event of button but with the button itself as this not the dialog object. I saw somewhere to call

buttons['OK'].apply(dialog);

but my buttons have absolutely no apply function!

I'm not sure what can I do!


First of all, you need to get buttons[0] not buttons['OK'], then, it's not a function it's an object, try to get to click function like this :

buttons[0].click.apply(dialog);


$('.ui-button:contains("Ok")').click()


What I use is:

// Get the buttons
var buttons = $("#myDialog").dialog("option", "buttons");
// Calls the event
buttons["OK"]();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜