How to open a jQuery Mobile Dialog from javascript?

删除回忆录丶 提交于 2019-11-28 19:08:17
codef0rmer

Add <a> tag anywhere in your page, just put your dialog's id as href as shown below: <a id='lnkDialog' href="#dialog" data-rel="dialog" data-transition="pop" style='display:none;'></a>

And replace $("#dialog").dialog(); inside your success event with $("#lnkDialog").click();

I think that this one is much more elegant:

$.mobile.changePage('#dialog', 'pop', true, true);

you should have in your html data-role="dialog" instead of page

<div data-role="dialog" id="dialog">...</div>

This answer also works:

    $.mobile.changePage('#myPage', {transition: 'pop', role: 'dialog'});   
Ahmet Mehmet

if it is not important to use "dialog" or "popup", try this:

$("#dialog").popup('open');

correct way with latest query version

$.mobile.changePage("#dialog", { transition: "pop",role: "dialog" })

As of JQM 1.4 the changePage has been deprecated, and will be removed in 1.5 (http://api.jquerymobile.com/jQuery.mobile.changePage/)

They suggest that one should use the change() method of pagecontainer instead.

$.mobile.pageContainer.pagecontainer("change", "#dialog", { transition: 'pop', role: "dialog" });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!