【问题标题】:Jquery Mobile Button breaks and further breaks layoutJquery Mobile Button 打破并进一步打破布局
【发布时间】:2011-05-27 18:05:32
【问题描述】:

我刚刚开始使用 JQuery Mobile 构建移动网站。我正在做一个非常简单的设计 - 只是一个图像、一些文本和一个链接到类似简单页面的按钮。我注意到,当我单击第一页上的按钮时,它会中断 - 看起来它被设置为 height: 100%,就在页面过渡之前。

然后,当我按下后退按钮查看初始页面时,该按钮已移动到屏幕的最顶部。我对 Jquery Mobile 很陌生,所以我不太了解它们是如何格式化的,这使得调试非常困难。

为了进一步向自己证明我没有疯,我直接从JQuery Mobile Docs 复制了非常基本的多页布局。此页面有效,直到我使用 data-role="button" 将链接更改为按钮。

这是我网站的代码。或者,您可以在http://www.printartsportal.com/mobileContact查看实际页面

<html>
<head>
<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>

<!-- Start of first page -->
<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 data-role="button" href="#bar">bar</a></p>
        </div><!-- /content -->

        <div data-role="footer">
                <h4>Page Footer</h4>
        </div><!-- /header -->
</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 first in the source order so I'm shown as the page.</p>
                <p><a href="#foo">Back to foo</a></p>
        </div><!-- /content -->

        <div data-role="footer">
                <h4>Page Footer</h4>
            </div><!-- /header -->
</div><!-- /page -->
</body>
</html>

编辑:这似乎只发生在 Chrome 和 Droid 2 Global 上的默认浏览器中(或者,至少它确实在 FF 中工作)。同样有趣的是,在 Chrome 中使用代码检查器时,突出显示按钮元素会在它应该的位置显示一个蓝色小框,但按钮仍位于页面顶部。

更新 1: 事情变得更奇怪了。 Phil Pafford 发布了一个jsfiddle,代码完美运行。我复制了小提琴用于 jquery/jqm.js/jqm.css 的确切链接,并将该 HTML 重新复制到我的文件中。我仍然遇到问题!

【问题讨论】:

    标签: jquery android mobile formatting jquery-mobile


    【解决方案1】:

    我相信这是issue 1565 和/或issue 1420 的结果。两者都应该在最新的(a4.1 后)版本中得到修复。

    我在运行 Android 2.2 的 HTC Evo 上的具体用例,失败并显示 a4.1,成功显示 test

    页面和对话框 -> 页面剖析 -> 查看样板模板 -> 返回

    在您的示例中,替换以下行:

    &lt;script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"&gt;&lt;/script&gt;

    与

    &lt;script type="text/javascript" src="http://code.jquery.com/mobile/latest/jquery.mobile.js"&gt;&lt;/script&gt;

    【讨论】:

    • 这些问题都不像我遇到的那样。事实上,运行 issue 1565 中提供的链接不会产生帖子中描述的错误(至少在我的浏览器中)。
    • 我在 Chrome 上尝试了您的确切示例。将第 5 行更改为以下内容可以解决后面的问题:
    • @jwegner 更新了我上面的答案,描述了要在您的代码中进行的更改
    • 完美运行..现在我只需要为“最新”移动到真正版本的时候做好准备..然后变成一个破碎的测试版增益:)
    【解决方案2】:

    嗯,在 jsfiddle 上使用您的代码可以按预期工作:http://jsfiddle.net/S9yXK/

    我的建议是下载 jQM 并在本地使用库,因为 jQM 演示站点可能存在问题。

    注意:我确实看到他们一直在更改 JS 和 HTML,他们非常喜欢在演示站点上进行测试。

    下载:http://jquerymobile.com/download/

    【讨论】:

    • 我将您的小提琴使用的确切链接复制并粘贴到我的代码中。我还将该小提琴中的确切 HTML 重新复制到了最小版本中。仍然遇到问题。这太离奇了。
    • 测试站点会自动替换为每日来自 repo 的最新版本,但 demos/1.0a4.1/ 不应经常更改。那改变了吗?
    • @naugtur 大部分时间我都会点击第一个演示页面查看源代码。前几天它看起来已经变成了测试版。我什至在推特上询问 jQM 是否即将推出测试版,他们一定是在演示网站上发布它时犯了一个错误。他们回答说:“很抱歉造成混乱......”
    • 至少我们知道不会再有 alpha 了;)
    猜你喜欢
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多