下载 jQuery

介绍如何从jQuery官方网站下载jQuery库文件,包括不同版本的下载链接和选择建议。

jQuery 官方下载

访问官方网站

jQuery 的官方下载地址是:https://jquery.com/download/

在这个页面上,你可以找到所有版本的 jQuery 下载链接。

下载选项

jQuery 提供了两种格式的下载文件:

1. 未压缩的 jQuery 文件

  • 文件名:jquery-3.6.0.js
  • 文件大小:约 280KB
  • 用途:开发和调试
  • 特点:代码格式化,包含注释

2. 压缩的 jQuery 文件

  • 文件名:jquery-3.6.0.min.js
  • 文件大小:约 90KB
  • 用途:生产环境
  • 特点:代码压缩,去除注释和空格

下载步骤

  1. 打开浏览器,访问 https://jquery.com/download/
  2. 找到 "Download the compressed, production jQuery 3.6.0" 链接
  3. 右键点击链接,选择"链接另存为"
  4. 选择保存位置,点击保存

或者:

  1. 找到 "Download the uncompressed, development jQuery 3.6.0" 链接
  2. 右键点击链接,选择"链接另存为"
  3. 选择保存位置,点击保存

版本选择

jQuery 有三个主要版本系列:

版本IE 支持文件大小推荐场景
1.xIE6+较大需要兼容旧版 IE
2.xIE9+中等不需要兼容 IE6-8
3.xIE9+较小现代浏览器项目

下载示例代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery 下载指南</title>
<style>
  .container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: Arial, sans-serif;
  }
  .download-section {
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
  }
  .download-btn {
    display: inline-block;
    padding: 12px 24px;
    margin: 10px 5px;
    background-color: #3498db;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    transition: background-color 0.3s;
  }
  .download-btn:hover {
    background-color: #2980b9;
  }
  .download-btn.min {
    background-color: #2ecc71;
  }
  .download-btn.min:hover {
    background-color: #27ae60;
  }
  .version-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
  }
  .version-table th, .version-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
  }
  .version-table th {
    background-color: #3498db;
    color: white;
  }
  .version-table tr:hover {
    background-color: #f5f5f5;
  }
  .info-box {
    padding: 15px;
    background-color: #fff3cd;
    border-left: 4px solid #ffc107;
    border-radius: 5px;
    margin: 15px 0;
  }
</style>
</head>
<body>

<div class="container">
  <h1>jQuery 下载指南</h1>

  <div class="download-section">
    <h3>jQuery 3.6.0 下载</h3>
    <p>选择适合你需求的版本:</p>
    <a href="https://code.jquery.com/jquery-3.6.0.js" class="download-btn" download>下载开发版</a>
    <a href="https://code.jquery.com/jquery-3.6.0.min.js" class="download-btn min" download>下载生产版</a>
    
    <div class="info-box">
      <p><strong>开发版</strong>:包含注释和格式化代码,便于调试</p>
      <p><strong>生产版</strong>:代码压缩,体积更小,适合线上使用</p>
    </div>
  </div>

  <div class="download-section">
    <h3>版本对比</h3>
    <table class="version-table">
      <thead>
        <tr>
          <th>版本</th>
          <th>IE 支持</th>
          <th>文件大小</th>
          <th>推荐场景</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>jQuery 1.x</td>
          <td>IE6+</td>
          <td>约 290KB</td>
          <td>需要兼容旧版 IE</td>
        </tr>
        <tr>
          <td>jQuery 2.x</td>
          <td>IE9+</td>
          <td>约 240KB</td>
          <td>不需要兼容 IE6-8</td>
        </tr>
        <tr>
          <td>jQuery 3.x</td>
          <td>IE9+</td>
          <td>约 280KB</td>
          <td>现代浏览器项目</td>
        </tr>
      </tbody>
    </table>
  </div>

  <div class="download-section">
    <h3>下载测试</h3>
    <button onclick="testDownload()" style="padding: 10px 20px; background-color: #3498db; color: white; border: none; border-radius: 5px; cursor: pointer;">测试下载链接</button>
    <div id="downloadTest" style="margin-top: 15px; padding: 15px; background-color: #e8f5e9; border-radius: 5px; display: none;"></div>
  </div>
</div>

<script>
function testDownload() {
  var urls = [
    'https://code.jquery.com/jquery-3.6.0.js',
    'https://code.jquery.com/jquery-3.6.0.min.js'
  ];
  
  $("#downloadTest").show().html("<p>正在测试下载链接...</p>");
  
  var completed = 0;
  var results = [];
  
  urls.forEach(function(url) {
    $.get(url)
      .done(function() {
        var type = url.includes('.min.js') ? '生产版' : '开发版';
        results.push(`<p><strong>✓ ${type}</strong>:${url}</p>`);
        completed++;
        if (completed === urls.length) {
          $("#downloadTest").html(results.join('') + '<p><strong>所有下载链接均可正常访问!</strong></p>');
        }
      })
      .fail(function() {
        completed++;
        if (completed === urls.length) {
          $("#downloadTest").html("<p><strong>✗ 部分链接无法访问,请检查网络连接</strong></p>");
        }
      });
  });
}
</script>

</body>
</html>

其他下载方式

GitHub 下载

你也可以从 GitHub 仓库下载 jQuery:

  1. 访问 https://github.com/jquery/jquery
  2. 点击 "Code" 按钮
  3. 选择 "Download ZIP"

NPM 下载

如果你使用 Node.js,可以通过 NPM 下载:

npm install jquery

Bower 下载

bower install jquery

下载后的使用

下载完成后,将文件放到项目的合适位置,然后在 HTML 中引入:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>使用本地 jQuery</title>
</head>
<body>

<h1>jQuery 本地文件测试</h1>
<button id="testBtn">点击测试</button>
<p id="result"></p>

<script src="jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
  $("#testBtn").click(function(){
    $("#result").text("本地 jQuery 文件加载成功!");
  });
});
</script>

</body>
</html>

总结

下载 jQuery 是使用它的第一步。根据你的需求选择合适的版本:

  • 开发调试:下载未压缩版本
  • 生产部署:下载压缩版本
  • 兼容旧 IE:选择 1.x 版本
  • 现代浏览器:选择 3.x 版本

下载后,记得将文件放在项目的合适位置,并在 HTML 中正确引入。