我正在尝试使用Jquery mobile
创建一个对话框。我试图引用已接受的答案in this SO question,但它对我不起作用。
这是我的代码:
<div data-role="page" id="first">
<!-- Code -->
<div id = "dialog" data-rel="dialog">
<div id = "errorText"></div>
<button id = "closeDialog">OK</button>
</div>
</div>
这是制作它的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();
当达到创建对话框的代码时,没有任何反应。建议?
答案 0 :(得分:14)
该对话框应该是一个单独的页面div,您可以通过Ajax加载或包含在HTML中。这是一个例子。
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Sample</h1>
</div>
<div data-role="content">
<p></p>
<p><a href="dialog.html" data-rel="dialog" data-role="button">Is this a question?</a></p>
</div>
</div>
<div data-role="page" data-url="dialog.html">
<div data-role="header">
<h1>Dialog</h1>
</div>
<div data-role="content">
<p>Is this an answer?</p>
</div>
</div>
</body>
</html>
答案 1 :(得分:11)
这对我有用,来自http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-pages.html
的“本地,内部链接”页面“”部分http://jsfiddle.net/homer2/ra7Hv/
<div data-role="page" id="foo">
<div data-role="header">
<h1>
Foo
</h1>
</div><!-- /header -->
<div data-role="content">
<p>
I'm first in the source order so I'm shown as the page.
</p>
<p>
View internal page called <a href="#bar" data-rel="dialog">bar</a>
</p>
</div><!-- /content -->
<div data-role="footer">
<h4>
Page Footer
</h4>
</div><!-- /footer -->
</div><!-- /page -->
<!-- Start of second page -->
<div data-role="page" id="bar">
<div data-role="header">
<h1>
Bar
</h1>
</div><!-- /header -->
<div data-role="content">
<p>
I'm second in the source order so I'm not shown as the page initally.
</p>
<p>
<a href="#foo">Back to foo</a>
</p>
</div><!-- /content -->
<div data-role="footer">
<h4>
Page Footer
</h4>
</div><!-- /footer -->
</div><!-- /page -->
答案 2 :(得分:2)
您可以使用
$('#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
的更多信息答案 3 :(得分:2)
就是这样,
<div data-role="popup" id="popupDialog" data-overlay-theme="a">
Hello world
</div>
$('#popupDialog' ).popup('open');
答案 4 :(得分:1)
我做了一个从JavaScript打开的通用对话框。我希望这会对你有所帮助。
HTML
代码:
<div data-role="page" id="genericDialog">
<div data-role="header" ><h3 id="genericDialogHeader"></h3></div>
<div data-role="content" id="genericDialogContent"></div>
</div>
JavaScript
代码:
function openDialog (title,body) {
//Setting values
$("#genericDialogHeader").html(title);
$("#genericDialogContent").html(body);
//Showing the generic dialog
$.mobile.changePage( "#genericDialog", { role: "dialog" } );
}