【问题标题】:Very weird behavior of $.mobile.changePage in a very simple jQuery Mobile page$.mobile.changePage 在一个非常简单的 jQuery Mobile 页面中的非常奇怪的行为
【发布时间】:2012-02-25 14:26:32
【问题描述】:

我正在使用 jQuery mobile(和 Phonegap,但以下内容与设备无关)为移动设备编写一个 Html 5 应用程序,使用一个包含各种

元素的 html 页面作为子页面。要在一个子页面和另一个子页面之间切换,我使用 $.mobile.changePage。 一切正常除非我将 div 标签放入其中一个
容器中!

工作示例:

<!DOCTYPE html>
<html>
<head>
    <title>App</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $.mobile.changePage($('#page2'), {
                transition : 'slideup',
                reverse : false,
                changeHash : true
            });
        });

    </script>
</head>
<body>
    <div data-role="page" id="page1" data-theme="a">
        <div data-role="content">
            Page1
        </div>
    </div>
    <div data-role="page" id="page2" data-theme="a">
        <div data-role="content">
            Page2
        </div>
    </div>
</body>
</html>

现在,在 Page1 后面添加像封闭 div 标签这样简单的东西之后

Page1 -> Page1<div />

$.mobile.changePage 仍然触发 - 可以看到 page2 内容一秒钟 - 但随后显示空白屏幕。

这发生在桌面浏览器和智能手机中(使用 Phonegap 并调整代码)。

我真的很感激任何想法或提示。缩小这个问题的范围并使其可重现使我花费了宝贵的生命时间,因为它似乎不太可能......

【问题讨论】:

    标签: jquery-mobile


    【解决方案1】:

    改变

    Page1<div />
    

    Page1</div>
    

    ...

    Page1<div>test</div> 
    

    也可以。

    不知道为什么 jqm 对空 div 的尾随 / 有问题。

    【讨论】:

    • 你说得对,这行得通。我使用带有 id 的空 div 来添加 html 内容,但玩得还不够。可能只是一个 jqm 错误。非常感谢!
    • 我相信 div 是一个自闭合元素,所以从语法上讲这是不正确的
    猜你喜欢
    • 2018-04-02
    • 1970-01-01
    • 2012-09-20
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2011-03-01
    • 1970-01-01
    相关资源
    最近更新 更多