jquery ui Dialog: cannot call methods on dialog prior to initialization

后端 未结 11 1920
既然无缘
既然无缘 2020-11-27 02:52

I have an app on jquery 1.5 with dialogs worked fine. While I have a lot of .live handlers, I changed this to .on. For that, I have to update jquery (now 1.8.3 an jquerui 1.

11条回答
  •  时光取名叫无心
    2020-11-27 03:44

    If you cannot upgrade jQuery and you are getting:

    Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'
    

    You can work around it like so:

    $(selector).closest('.ui-dialog-content').dialog('close');
    

    Or if you control the view and know no other dialogs should be in use at all on the entire page, you could do:

    $('.ui-dialog-content').dialog('close');
    

    I would only recommend doing this if using closest causes a performance issue. There are likely other ways to work around it without doing a global close on all dialogs.

提交回复
热议问题