jquery - 如何使用 jQuery mobile 创建覆盖框

标签 jquery jquery-mobile

我知道我可以创建一个 jQuery 移动覆盖,从另一个页面加载内容。

我可以手动创建叠加层来向用户显示消息吗?有比标准 JS 警报框更性感的东西吗?

更新

而不是说

<a href="my_message.html" data-rel="dialog">Show Message</a>

我想说的是:

$.showDialog("Hello world!");

最佳答案

为您指明正确的方向:

相关:

实例:

JS:

var originalMessage = $('#the-content').html();
var dynamicMessage  = '<span>This is a dynamic message</span>'; // add dynamic content here

$('#dynamic').click(function() {
    $('#generic-dialog').live('pagebeforeshow',function(event, ui) {
        $('#the-content').html(dynamicMessage).trigger('create');
    }); 
});

$('#original').click(function() {
    $('#generic-dialog').live('pagebeforeshow',function(event, ui) {
        $('#the-content').html(originalMessage).trigger('create');
    });
});

HTML:

<div data-role="page" id="home">
    <div data-role="content">
        <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f" id="tasks">
            <li data-role="list-divider">Dynamic Dialog</li>
            <li><a href="#generic-dialog" data-rel="dialog" id="original">Show Original Dialog</a></li>
            <li><a href="#generic-dialog" data-rel="dialog" id="dynamic">Show Dynamic Dialog</a></li>
        </ul>
    </div>
</div>

<!-- This is a page used for a dialog -->
<div data-role="page" id="generic-dialog">

    <div data-role="header" data-theme="d">
        <h1>Dialog</h1>
    </div>

    <div data-role="content" data-theme="c" id="the-content">
        <h1>Delete page?</h1>
        <p>This is a regular page, styled as a dialog. To create a dialog, just link to a normal page and include a transition and <code>data-rel="dialog"</code> attribute.</p>
        <a href="#" data-role="button" data-rel="back" data-theme="b">Sounds good</a>       
        <a href="#" data-role="button" data-rel="back" data-theme="c">Cancel</a>    
    </div>
</div>

关于jquery - 如何使用 jQuery mobile 创建覆盖框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7770383/

相关文章:

javascript - Chrome/FF 中的对象处理?

jquery - jquery mobile 中的日期选择器在第二页中添加时是重复的

android - 在phonegap中打开软键盘时,showkeyboard/hidekeyboard事件不会在ios 7上触发

javascript - 在 jQuery Mobile 对话框中设置文本不起作用

javascript - 无法在已绑定(bind)数据的标签内绑定(bind)数据 Knockout js

ajax 函数回调中的 jQuery xhr 对象属性

javascript - jQuery Mobile 显示/隐藏基于选择字段的表单输入

iphone - iPhone 上的 jQuery Mobile + PhoneGap 无法加载页面

javascript - Jquery 对象在排序后未定义,但在 firebug 中

jQuery .slideUp() 在 Chrome 中不起作用