前端笔记
长乐王

什么是jQuery?jQuery简介

jQuery 简介
jQuery 是一个 JavaScript 库。jQuery 极大地简化了 JavaScript 编程。
jQuery 是一个“写的更少,但做的更多”的轻量级 JavaScript 库。
<!DOCTYPE html>
<html>
<head>
<script src="../jquery/jquery-1.11.1.min.js"></script>
<script>
    $(document).ready(function(){
        $("p").click(function(){
            $(this).hide();
        });
    });
</script>
</head>
<body>
    <p>如果您点击我,我会消失。</p>
    <p>点击我,我会消失。</p>
    <p>也要点击我哦。</p>
</body>
</html>

jQuery 库
jQuery 库可以通过一行简单的标记被添加到网页中。
jQuery 是一个 JavaScript 函数库。jQuery 库包含以下特性:
    HTML 元素选取
    HTML 元素操作
    CSS 操作
    HTML 事件函数
    JavaScript 特效和动画
    HTML DOM 遍历和修改
    AJAX
    Utilities

向您的页面添加 jQuery 库
jQuery 库位于一个 JavaScript 文件中,其中包含了所有的 jQuery 函数。
可以通过下面的标记把 jQuery 添加到网页中:
<head>
    <script type="text/javascript" src="jquery.js"></script>
</head>
提示:请注意,<script> 标签应该位于页面的 <head> 部分。

基础 jQuery 实例
<html>
<head>
<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("button").click(function(){
            $("p").hide();
        });
    });
</script>
</head>
<body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">Click me</button>
</body>
</html>
注释:演示了 jQuery 的 hide() 函数,隐藏了 HTML 文档中所有的 <p> 元素。

下载 jQuery
共有两个版本的 jQuery 可供下载:一份是精简过的,另一份是未压缩的(供调试或阅读)。
这两个版本都可从 jQuery.com 下载,也可以直接加载网上提供的公用 CDN jQuery 核心文件。
例如,使用 Google 的 CDN 或 Microsoft 的 CDN:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
本文番号: 前端笔记 - jQuery - 什么是jQuery?jQuery简介

评论