gpt4 book ai didi

jquery - 默认的 jQuery Mobile CSS 样式不适用,已测试多个浏览器

转载 作者:行者123 更新时间:2023-11-28 01:23:38 24 4
gpt4 key购买 nike

我正在尝试尝试学习一些 jQuery Mobile,但无法应用基本的 CSS 样式。我正在引用来自 jQuery Mobile 网站的 css 链接,并且已连接到互联网(但也尝试将 css 本地加载到 html 中,但仍然不适用)

这是我的测试代码:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>2test</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />

<script src="http://code.jquery.com/jquery-1.4.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

</head>


<body>

<div data-role="page">
<div id="header" data-role="header">
<h1>My Photos</h1>
</div>

<article data-role="content">
<ul data-role="listview" data-filter="true">
<li>
<a href="#">
<h1>Miniature Doberman Pincher</h1>

<p>This is what happens when a
friend brings a dog to the studio.</p>
</a>
</li>
<li>
<a href="#">
<h1>Gummy Bears</h1>

<p>Three different poster boards...mirror for reflection,
black for background white for highlights</p>
</a>
</li>
</ul>


</article>

<footer data-role="footer" data-position="fixed">
<nav data-role="navbar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Photos</a></li>
<li><a href="#">Info</a></li>
</ul>
</nav>
</footer>
</div>


</body>


</html>

这是桌面版 Chrome 45 上的输出(编辑:旧屏幕截图,图像已删除):

enter image description here

以及我的 Android 设备 Chrome 45 上的输出(从托管站点访问):

enter image description here

两个输出都没有显示 jQuery Mobile 默认样式的预期“移动式”外观。我错过了什么?

最佳答案

我在控制台中看到以下错误。

Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME http://code.jquery.com/jquery-1.4.5.min.js Failed to load resource: the     server responded with a status of 404 (Not Found)
jquery.mobile-1.4.5.min.js:3 Uncaught TypeError: Cannot set property 'mobile' of undefined

我认为这是由 JQM 尝试解析本地文件的 url 并失败导致 JS 失败造成的。要修复删除对本地文件路径的引用,而是使用相对路径。

实际上,您的某些 JQM 路径看起来可能不正确:

<!-- add this link here -->
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<!-- remove your link here -->
<!-- <script src="http://code.jquery.com/jquery-1.4.5.min.js></script> -->

参见 jQuery Mobile getting started error也需要在 JQM 之前包含 jquery include 或使用 bundle。

编辑:实际上你有很多问题。 JQM 对 DOM/HTML 的操作比您可能习惯的要多得多,并且具有比您在其他样式框架中发现的更严格的结构。您需要考虑单页应用程序。页面必须在文件中定义。我认为您需要查看文档以了解 JQM 是什么。

根据 http://demos.jquerymobile.com/1.4.5/intro/

A page in jQuery Mobile consists of an element with a data-role="page" attribute. Within the "page" container, any valid HTML markup can be used, but for typical pages in jQuery Mobile, the immediate children of a "page" are divs with data-role="header", class="ui-content", and data-role="footer". The baseline requirement for a page is only the page wrapper to support the navigation system, the rest is optional.

JQM 开始时可能有点困惑 - 页面 div 是绝对必需的。您最好先从示例中复制和粘贴并尝试示例,但要获得样式,您需要将内容包装在页面 div 中..

<div data-role="page">
...
</div>

对于没有图像的示例的工作版本,请参见 http://jsfiddle.net/shotgundriver/8mb0rzhy/

关于jquery - 默认的 jQuery Mobile CSS 样式不适用,已测试多个浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32919719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com