我试图用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();
当创建对话框的代码没有发生什么.建议?
解决方法
对话框应该是一个单独的页面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>