jquery - 创建对话框 JQuery Mobile

标签 jquery jquery-mobile

我正在尝试使用 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>

关于jquery - 创建对话框 JQuery Mobile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6101370/

相关文章:

javascript - jQuery Mobile - 移至下一页/上一页 - 单击后执行操作两次

jquery - 检测较旧的 IE 版本

javascript - 在 contentEditable div 中显示上下文菜单

javascript - 停止倒数计时器 Javascript onClick

ajax - 你能在 ajax 响应事件上做一个 jquery 移动弹出窗口吗?

vb.net - 使用 JQuery Mobile 的 asp 图像按钮单击事件

jquery - jquery 和 jquery mobile 的哪种 CDN 将在移动设备上提供最佳加载速度?

javascript - opencart 在类别页面添加到购物车而不将商品添加到购物车

performance - Jquery Mobile + Phonegap 提高 ListView 性能

css - 带有标签垂直对齐的 JQuery Mobile slider