创建一个JQuery Mobile对话框

我正在尝试使用Jquery mobile创建一个对话框。 我试图在这个SO问题中提到已接受的答案,但它对我不起作用。

这是我的代码:

  

这里是JS(在函数内部):

 //Nothing checked. Cannot continue. Add error message to div $('#errorText').html("You must check the checkbox next to \"I Agree\" to continue"); //Open Dialog $('#dialog').dialog(); 

当达到创建对话框的代码时,没有任何反应。 建议?

该对话框应该是一个单独的页面div,您可以通过Ajax加载或包含在HTML中。 这是一个例子。

    Page Title       

Dialog

Is this an answer?

这对我有用,来自http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-pages.html的“本地,内部链接”页面“”部分

http://jsfiddle.net/homer2/ra7Hv/

 

Foo

I'm first in the source order so I'm shown as the page.

View internal page called bar

Page Footer

Bar

I'm second in the source order so I'm not shown as the page initally.

Back to foo

Page Footer

你可以用

 $('#errorText').html("You must check the checkbox next to \"I Agree\" to continue"); $.mobile.changePage('dialog', 'slide', false, false); 

有关http://jquerymobile.com/demos/1.0b1pre/#/demos/1.0b1pre/docs/pages/docs-navmodel.html的更多信息

只是这个,

 
Hello world
$('#popupDialog' ).popup('open');

我做了一个从JavaScript打开的通用对话框。 我希望这能帮到您。

HTML代码:

 

JavaScript代码:

 function openDialog (title,body) { //Setting values $("#genericDialogHeader").html(title); $("#genericDialogContent").html(body); //Showing the generic dialog $.mobile.changePage( "#genericDialog", { role: "dialog" } ); }