jQuery Mobile 安装

jQuery Mobile 安装指南

jQuery Mobile 已于 2021 年停止维护(最新版 1.4.5)。
以下安装方式仅适用于 学习、维护旧项目或内网部署不推荐用于新项目


安装方式一览

方式推荐度说明
CDN(推荐)⭐⭐⭐⭐快速、无需下载、自动缓存
下载本地文件⭐⭐⭐适合离线/内网环境
npm / Yarn⭐⭐仅用于构建工具(如 Webpack)
Bower(已废弃)不推荐

方式 1:使用 CDN(最简单,推荐)

直接在 <head> 中引入:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery Mobile 页面</title>

  <!-- 1. jQuery Mobile CSS -->
  <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />

  <!-- 2. jQuery Core -->
  <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>

  <!-- 3. jQuery Mobile JS -->
  <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
  <div data-role="page">
    <div data-role="header"><h1>安装成功!</h1></div>
    <div data-role="main" class="ui-content">
      <p>你已成功加载 jQuery Mobile。</p>
    </div>
  </div>
</body>
</html>

CDN 地址(官方,长期可用)

  • CSS: https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css
  • JS: https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js
  • jQuery: https://code.jquery.com/jquery-1.11.1.min.js(或 2.x / 3.x 兼容版)

方式 2:下载本地文件(离线使用)

步骤:

  1. 访问官方下载页(归档):
    https://jquerymobile.com/download/
  2. 或直接下载 1.4.5 ZIP 包
    https://jquerymobile.com/resources/download/jquery.mobile-1.4.5.zip
  3. 解压后结构:
   jquery.mobile-1.4.5/
   ├── css/
   │   └── jquery.mobile-1.4.5.min.css
   ├── js/
   │   └── jquery.mobile-1.4.5.min.js
   └── images/  (图标 sprites)
  1. 引入本地文件:
<link rel="stylesheet" href="jquery.mobile-1.4.5/css/jquery.mobile-1.4.5.min.css">
<script src="jquery-1.11.1.min.js"></script>
<script src="jquery.mobile-1.4.5/js/jquery.mobile-1.4.5.min.js"></script>

注意:必须放入 images/ 文件夹,否则图标(如返回箭头)会丢失!


方式 3:使用 npm(现代构建工具)

npm install jquery-mobile@1.4.5

然后在 Webpack / Vite 中引入:

import 'jquery-mobile/dist/jquery.mobile.min.css';
import $ from 'jquery';
import 'jquery-mobile';

注意:需配置 copy-webpack-plugin 复制 images/ 目录


完整本地安装示例(推荐结构)

my-jqm-app/
├── index.html
├── jquery-1.11.1.min.js
└── jquery.mobile-1.4.5/
    ├── css/
    ├── js/
    └── images/

index.html 内容:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>本地 jQM</title>
  <link rel="stylesheet" href="jquery.mobile-1.4.5/css/jquery.mobile-1.4.5.min.css">
  <script src="jquery-1.11.1.min.js"></script>
  <script src="jquery.mobile-1.4.5/js/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
  <div data-role="page">
    <div data-role="header"><h1>离线运行</h1></div>
    <div data-role="main" class="ui-content">
      <p>无需网络即可运行!</p>
    </div>
  </div>
</body>
</html>

常见问题(FAQ)

问题解决方案
图标不显示确保 images/ 文件夹与 CSS 同目录
点击无反应检查 jQuery 是否在 jQM 之前 引入
样式错乱确保 <meta viewport> 已添加
中文乱码添加 <meta charset="utf-8">
想自定义主题使用 ThemeRoller 归档版 下载 CSS

一键安装脚本(Linux/macOS)

#!/bin/bash
mkdir jqm-app && cd jqm-app

# 下载 jQuery
curl -O https://code.jquery.com/jquery-1.11.1.min.js

# 下载 jQuery Mobile
curl -L -O https://jquerymobile.com/resources/download/jquery.mobile-1.4.5.zip
unzip jquery.mobile-1.4.5.zip

# 创建测试页面
cat > index.html << 'EOF'
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQM 本地安装</title>
<link rel="stylesheet" href="jquery.mobile-1.4.5/css/jquery.mobile-1.4.5.min.css">
<script src="jquery-1.11.1.min.js"></script>
<script src="jquery.mobile-1.4.5/js/jquery.mobile-1.4.5.min.js"></script>
</head><body>
<div data-role="page">
  <div data-role="header"><h1>安装成功!</h1></div>
  <div data-role="main" class="ui-content"><p>本地运行正常。</p></div>
</div>
</body></html>
EOF

echo "安装完成!打开 index.html 查看效果。"

总结:推荐安装方式

场景推荐方式
快速测试 / 学习CDN
内网 / 离线部署下载 ZIP + 本地引入
现代项目构建npm + Webpack(不推荐 jQM 本身)

下载链接汇总

文件链接
jQuery Mobile 1.4.5 ZIPhttps://jquerymobile.com/resources/download/jquery.mobile-1.4.5.zip
jQuery 1.11.1https://code.jquery.com/jquery-1.11.1.min.js
CDN CSShttps://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css
CDN JShttps://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js

需要我打包一个 完整可运行的 ZIP 项目模板(含 images/)发给你吗?
或帮你 迁移到 Bootstrap 5?随时说!

文章已创建 2588

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部