• jQuery的学习(一篇文章齐全)


    目录

    Day29 jQuery

    1、jQuery介绍

    2、jQuery的选择器

    2.1、直接查找

    2.2、导航查找

    3、jQuery的绑定事件

    案例1:绑定取消事件

    案例2:模拟事件触发

    4、jQuery的操作标签

    tab切换案例jQuery版本:

    案例1:

    案例2:clone案例

    案例3:返回顶部

    案例4:位置偏移

    5、jQuery的动画

    5.1、基本方法

    案例:动画显示

    5.2、自定义动画

    6、扩展方法 (插件机制)


    Day29 jQuery

    1、jQuery介绍

    • jQuery是什么

    jQuery是一个快速、简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架)。jQuery设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。它封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作、事件处理、动画设计和Ajax交互。

    jQuery的核心特性可以总结为:具有独特的链式语法和短小清晰的多功能接口;具有高效灵活的css选择器,并且可对CSS选择器进行扩展;拥有便捷的插件扩展机制和丰富的插件。jQuery兼容各种主流浏览器,如IE 6.0+、FF 1.5+、Safari 2.0+、Opera 9.0+等

    • jQuery的版本

    目前在市场上, 1.x , 2.x, 3.x 功能的完善在1.x, 2.x的时候是属于删除旧代码,去除对于旧的浏览器兼容代码。3.x的时候增加es的新特性以及调整核心代码的结构

    • jQuery的引入

    根本上jquery就是一个写好的js文件,所以想要使用jQuery的语法必须先引入到本地

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js">script>
    • jQuery的基本语法

    $().方法()
    ​
    1 查找标签
    2 .方法 操作标签

    • jQuery对象和dom对象的关系

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    
    7.    <script src="jquery3.6.js">script>
    8. head>
    9. <body>
    10. <ul class="c1">
    11.    <li>123li>
    12.    <li>234li>
    13.    <li>345li>
    14. ul>
    15. <script>
    16.       // $(".c1 li").css("color","red");
    17.       console.log($(".c1 li"));   // dom集合对象 [dom1,dom2,...]
    18.       // 如何将jQury对象转换为Dom对象
    19.       console.log($(".c1 li")[1].innerHTML);
    20.       // 如何将Dom对象转换为jQuery对象;
    21.       var ele = document.querySelector(".c1 li");
    22.       // console.log(ele);
    23.       // ele.style.color = "red";
    24.      $(ele).css("color","orange")  // [ele]
    25. script>
    26. body>
    27. html>

    2、jQuery的选择器

    2.1、直接查找

    • 基本选择器

    1. /*
    2. #id # id选择符
    3. element # 元素选择符
    4. .class # claw43ss选择符
    5. selector1, selector2, selectorN # 同时获取多个元素的选择符
    6. $("#id")
    7. $(".class")
    8. $("element")
    9. $(".class,p,div")
    10. */
    • 组合选择器

    1. /*
    2. ancestor descendant // 包含选择符
    3. parent > child // 父子选择符
    4. prev + next // 下一个兄弟选择符
    5. prev ~ siblings // 兄弟选择符
    6. $(".outer div")
    7. $(".outer>div")
    8. $(".outer+div")
    9. $(".outer~div")
    10. */
    • 属性选择器

    1. /*
    2. [attribute=value]   // 获取拥有指定数据attribute,并且置为value的元素
    3. $('[type="checked"]')  
    4. $('[class*="xxx"]')  
    5. */
    • 表单选择器

    1. /*
    2. $("[type='text']")----->$(":text")         注意只适用于input标签 : $("input:checked")
    3. 同样适用表单的以下属性
    4. :enabled
    5. :disabled
    6. :checked
    7. :selected
    8. */
    • 筛选器

    1. /*
    2. // 筛选器
    3. :first               // 从已经获取的元素集合中提取第一个元素
    4. :even               // 从已经获取的元素集合中提取下标为偶数的元素
    5. :odd                 // 从已经获取的元素集合中提取下标为奇数的元素
    6. :eq(index)           // 从已经获取的元素集合中提取指定下标index对应的元素
    7. :gt(index)           // 从已经获取的元素集合中提取下标大于index对应的元素
    8. :last               // 从已经获取的元素集合中提取最后一个元素
    9. :lt(index)           // 从已经获取的元素集合中提取下标小于index对应的元素
    10. :first-child         // 从已经获取的所有元素中提取他们的第一个子元素
    11. :last-child         // 从已经获取的所有元素中提取他们的最后一个子元素
    12. :nth-child           // 从已经获取的所有元素中提取他们的指定下标的子元素
    13. // 筛选器方法
    14. $().first()         // 从已经获取的元素集合中提取第一个元素
    15. $().last()           // 从已经获取的元素集合中提取最后一个元素
    16. $().eq()             // 从已经获取的元素集合中提取指定下标index对应的元素
    17. */

    2.2、导航查找

    1. /*
    2. // 查找子代标签:        
    3. $("div").children(".test")    
    4. $("div").find(".test")  
    5.                              
    6. // 向下查找兄弟标签
    7. $(".test").next()              
    8. $(".test").nextAll()    
    9. $(".test").nextUntil()
    10.                          
    11. // 向上查找兄弟标签  
    12. $("div").prev()                  
    13. $("div").prevAll()      
    14. $("div").prevUntil()
    15. // 查找所有兄弟标签  
    16. $("div").siblings()  
    17.              
    18. // 查找父标签:        
    19. $(".test").parent()              
    20. $(".test").parents()    
    21. $(".test").parentUntil()
    22. */

    3、jQuery的绑定事件

    1. /*
    2. 三种用法:
    3. 1. on 和 off
    4. // 绑定事件
    5. $().on("事件名",匿名函数)
    6. // 解绑事件,给指定元素解除事件的绑定
    7. $().off("事件名")
    8.  
    9. 2. 直接通过事件名来进行调用
    10. $().事件名(匿名函数)               //简易版本的
    11. 等同于
    12. $().bind("事件名",匿名函数)
    13. 3. 组合事件,模拟事件
    14. $().ready(匿名函数)   // 入口函数
    15. $().hover(mouseover, mouseout)   // 是onmouseover和 onmouseout的组合
    16. $().trigger(事件名) // 用于让js自动触发指定元素身上已经绑定的事件
    17. */

    案例1:绑定取消事件

    1. <p>限制每次一个按钮只能投票3次p>
    2. <button id="zan">点下赞(<span>10span>)button>
    3. <script>
    4.    let zan = 0;
    5.    $("#zan").click(function(){
    6.        $("#zan span").text(function(){
    7.            zan++;
    8.            let ret = parseInt($(this).text())+1;
    9.            if(zan >= 3){
    10.                $("#zan").off("click"); // 事件解绑
    11.           }
    12.            return ret;
    13.       });
    14.   })
    15. script>

    案例2:模拟事件触发

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <script src="js/jquery-1.11.0.js">script>
    7.    <style>
    8.    input[type=file]{
    9.        display: none;
    10.   }
    11.    .upload{
    12.        width: 180px;
    13.        height: 44px;
    14.        border-radius: 5px;
    15.        color: #fff;
    16.        text-align: center;
    17.        line-height: 44px;
    18.        background-color: #000000;
    19.        border: none;
    20.        outline: none;
    21.        cursor: pointer;
    22.   }
    23.    style>
    24. head>
    25. <body>
    26.    <input type="file" name="avatar">
    27.    <button class="upload">上传文件button>
    28.    <script>
    29.    $(".upload").on("click", function(){
    30.       $("input[type=file]").trigger("click"); // 模拟事件的触发
    31.   });
    32.    script>
    33. body>
    34. html>

     

    4、jQuery的操作标签

    • 文本操作

    1. /*
    2. $("选择符").html()     // 读取指定元素的内容,如果$()函数获取了有多个元素,则提取第一个元素
    3. $("选择符").html(内容) // 修改内容,如果$()函数获取了多个元素, 则批量修改内容
    4. $("选择符").text()     // 效果同上,但是获取的内容是纯文本,不包含html代码
    5. $("选择符").text(内容) // 效果同上,但是修改的内容中如果有html文本,在直接转成实体字符,而不是html代码
    6. */
    • value操作

     $().val()

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <script src="jquery3.6.js">script>
    7.    <script>
    8.    $(function () {
    9.        $("#i1").blur(function () {
    10.            // 获取jquery对象的value属性值
    11.            console.log(this.value);
    12.            console.log($(this).val());
    13.            // 设置value属性值
    14.            $(this).val("hello world")
    15.       });
    16.        
    17.        $("#i3").change(function () {
    18.            console.log(this.value);
    19.            console.log($(this).val());
    20.            $(this).val("guangdong");
    21.       });
    22.        console.log($("#i2").val());
    23.        console.log($("#i2").val("hello pig!"))
    24.   })
    25.    script>
    26. head>
    27. <body>
    28. <input type="text" id="i1">
    29. <select  id="i3">
    30.    <option value="hebei">河北省option>
    31.    <option value="hubei">湖北省option>
    32.    <option value="guangdong">广东省option>
    33. select>
    34. <p> <textarea name="" id="i2" cols="30" rows="10">123textarea>p>
    35. body>
    36. html>
    • 属性操作

    /*
    //读取属性值
      $("选择符").attr("属性名");   // 获取非表单元素的属性值,只会提取第一个元素的属性值
      $("选择符").prop("属性名");   // 表单元素的属性,只会提取第一个元素的属性值
    ​
    //操作属性
      $("选择符").attr("属性名","属性值");  // 修改非表单元素的属性值,如果元素有多个,则全部修改
      $("选择符").prop("属性名","属性值");  // 修改表单元素的属性值,如果元素有多个,则全部修改
      
      $("选择符").attr({'属性名1':'属性值1','属性名2':'属性值2',.....})
      $("选择符").prop({'属性名1':'属性值1','属性名2':'属性值2',.....})
    */
    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <script src="jquery3.6.js">script>
    7.  
    8. head>
    9. <body>
    10. <button class="select_all">全选button>
    11. <button class="cancel">取消button>
    12. <button class="reverse">反选button>
    13. <hr>
    14. <table border="1">
    15.    <tr>
    16.        <td>选择td>
    17.        <td>姓名td>
    18.        <td>年龄td>
    19.    tr>
    20.    
    21.    <tr>
    22.        <td><input type="checkbox">td>
    23.        <td>张三td>
    24.        <td>23td>
    25.    tr>
    26.    <tr>
    27.        <td><input type="checkbox">td>
    28.        <td>李四td>
    29.        <td>23td>
    30.    tr>
    31.    <tr>
    32.        <td><input type="checkbox">td>
    33.        <td>王五td>
    34.        <td>23td>
    35.    tr>
    36. table>
    37. <script>
    38.    
    39.    $(".select_all").click(function () {
    40.        $("table input:checkbox").prop("checked",true);
    41.   });
    42.    $(".cancel").click(function () {
    43.       $("table input:checkbox").prop("checked",false);
    44.   });
    45.    $(".reverse").click(function () {
    46.       $("table input:checkbox").each(function () {
    47.           $(this).prop("checked",!$(this).prop("checked"))
    48.       })
    49.   });
    50. script>
    51. body>
    52. html>
    • css样式操作

    /*
    获取样式
    $().css("样式属性");   // 获取元素的指定样式属性的值,如果有多个元素,只得到第一个元素的值
    ​
    操作样式
    $().css("样式属性","样式值").css("样式属性","样式值");
    $().css({"样式属性1":"样式值1","样式属性2":"样式值2",....})
    ​
    $().css("样式属性":function(){
      
      // 其他代码操作 
      return "样式值";
    });
    */
    • class 属性操作

    $().addClass("class1  class2 ... ...")   // 给获取到的所有元素添加指定class样式
    $().removeClass() // 给获取到的所有元素删除指定class样式
    $().toggleClass() // 给获取到的所有元素进行判断,如果拥有指定class样式的则删除,如果没有指定样式则添加

    tab切换案例jQuery版本:

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <style>
    7.       *{
    8.            margin: 0;
    9.            padding: 0;
    10.       }
    11.        .tab{
    12.            width: 800px;
    13.            height: 300px;
    14.            /*border: 1px solid rebeccapurple;*/
    15.            margin: 200px auto;
    16.       }
    17.        .tab ul{
    18.            list-style: none;
    19.       }
    20.        .tab ul li{
    21.            display: inline-block;
    22.       }
    23.        .tab_title {
    24.            background-color: #f7f7f7;
    25.            border: 1px solid #eee;
    26.            border-bottom: 1px solid #e4393c;
    27.       }
    28.        .tab .tab_title li{
    29.            padding: 10px 25px;
    30.            font-size: 14px;
    31.       }
    32.        .tab .tab_title li.current{
    33.            background-color: #e4393c;
    34.            color: #fff;
    35.            cursor: default;
    36.       }
    37.        .tab_con li.hide{
    38.            display: none;
    39.       }
    40.    style>
    41.    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js">script>
    42. head>
    43. <body>
    44. <div class="tab">
    45.    <ul class="tab_title">
    46.        <li class="current">商品介绍li>
    47.        <li>规格与包装li>
    48.        <li>售后保障li>
    49.        <li>商品评论li>
    50.    ul>
    51.    <ul class="tab_con">
    52.        <li>商品介绍...li>
    53.        <li class="hide">规格与包装...li>
    54.        <li class="hide">售后保障...li>
    55.        <li class="hide">商品评论...li>
    56.    ul>
    57. div>
    58. <script>
    59.    // jQuery
    60.    $(".tab_title li").click(function (){
    61.           // current样式
    62.           $(this).addClass("current").siblings().removeClass('current');
    63.           // hide样式
    64.           $(".tab_con li").eq($(this).index()).removeClass("hide").siblings().addClass("hide")
    65.   })
    66. script>
    67. body>
    68. html>
    • 节点操作

    1. /*
    2. //创建一个jquery标签对象
    3.   $("<p>")
    4. //内部插入
    5.   $("").append(content|fn)       // $("p").append("<b>Hellob>");   父标签中追加一个子标签,放在最后
    6.   $("").appendTo(content)       // $("p").appendTo("div");           反过来:把子标签添加到父标签中,放在最后
    7.   $("").prepend(content|fn)     // $("p").prepend("<b>Hellob>");   父标签中加一个子标签,放在第一个
    8.   $("").prependTo(content)       // $("p").prependTo("#foo");   反过来:把子标签添加到父标签中,放在第一个中
    9. //外部插入
    10.   $("").after(content|fn)       // ("p").after("<b>Hellob>");
    11.   $("").before(content|fn)       // $("p").before("<b>Hellob>");
    12.   $("").insertAfter(content)     // $("p").insertAfter("#foo");
    13.   $("").insertBefore(content)   // $("p").insertBefore("#foo");
    14. //替换
    15.   $("").replaceWith(content|fn) // $("p").replaceWith("<b>Paragraph. b>");
    16. //删除
    17.   $("").empty()     // 只是把标签中的内容清空了,但是标签还在
    18.   $("").remove([expr])
    19. //复制
    20.   $("").clone([Even[,deepEven]])
    21. */

    案例1:

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <script src="jquery3.6.js">script>
    7. head>
    8. <body>
    9. <button class="add_btn">添加节点button>
    10. <button class="del_btn">删除节点button>
    11. <button class="replace_btn">替换节点button>
    12. <div class="c1">
    13.    <h3>hello JS!h3>
    14.    <h3 class="c2">hello worldh3>
    15. div>
    16. <script>
    17.    
    18.    $(".add_btn").click(function () {
    19.        // 创建jquery对象
    20.        // var $img = $("");
    21.        // $img.attr("src","https://img1.baidu.com/it/u=3210260546,3888404253&fm=26&fmt=auto&gp=0.jpg")
    22.        // 节点添加
    23.        // $(".c1").append($img);
    24.        // $img.appendTo(".c1")
    25.        // $(".c1").prepend($img);
    26.        // $(".c2").before($img);
    27.        // 支持字符串操作
    28.        $(".c1").append("")
    29.   });
    30.    $(".del_btn").click(function () {
    31.          $(".c2").remove();
    32.          // $(".c2").empty();
    33.   });
    34.    $(".replace_btn").click(function () {
    35.        // alert(123);
    36.        // var $img = $("");
    37.        // $img.attr("src","https://img1.baidu.com/it/u=3210260546,3888404253&fm=26&fmt=auto&gp=0.jpg")
    38.        // $(".c2").replaceWith($img);
    39.        $(".c2").replaceWith("");
    40.   })
    41.    
    42. script>
    43. body>
    44. html>

    案例2:clone案例

    1. <div class="outer">
    2.    <div class="item">
    3.        <input type="button" value="+" class="add">
    4.        <input type="text">
    5.    div>
    6. div>
    7. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js">script>
    8. <script>
    9.   $(".add").click(function () {
    10.       var $clone=$(this).parent().clone()
    11.       $clone.children(".add").attr({"value":"-","class":"rem"})
    12.       $(".outer").append($clone);
    13.   });
    14.    $('.rem').click(function () {
    15.        $(this).parent().remove()
    16.   });
    17.    // 事件委派
    18.    $(".outer").on("click",".item .rem",function () {
    19.        $(this).parent().remove()
    20.   })
    21. script>
    • css尺寸

    /*
    $("").height([val|fn])
    $("").width([val|fn])
    $("").innerHeight()
    $("").innerWidth()
    $("").outerHeight([soptions])
    $("").outerWidth([options])
    */
    • css位置

    /*
    $("").offset([coordinates])  // 获取匹配元素在当前视口的相对偏移。
    $("").position()             // 获取匹配元素相对父元素的偏移,position()函数无法用于设置操作。
    $("").scrollTop([val])       // 获取匹配元素相对滚动条顶部的偏移。
    */

    案例3:返回顶部

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <style>
    7.       *{
    8.            margin: 0;
    9.       }
    10.        .content{
    11.            height: 2000px;
    12.            background-color: lightgray;
    13.       }
    14.        .return_top{
    15.            width: 120px;
    16.            height: 50px;
    17.            background-color: lightseagreen;
    18.            color: white;
    19.            text-align: center;
    20.            line-height: 50px;
    21.            position: fixed;
    22.            bottom: 20px;
    23.            right: 20px;
    24.       }
    25.        .hide{
    26.            display: none;
    27.       }
    28.    style>
    29.    <script src="jquery3.6.js">script>
    30. head>
    31. <body>
    32. <div class="content">
    33.    <h3>文章...h3>
    34. div>
    35. <div class="return_top hide">返回顶部div>
    36. <script>
    37.    console.log($(window).scrollTop());
    38.    $(".return_top").click(function () {
    39.        $(window).scrollTop(0)
    40.        
    41.   });
    42.    $(window).scroll(function () {
    43.        console.log($(this).scrollTop());
    44.        var v =$(this).scrollTop();
    45.        if (v > 100){
    46.            $(".return_top").removeClass("hide");
    47.       }else {
    48.            $(".return_top").addClass("hide");
    49.       }
    50.   })
    51. script>
    52. body>
    53. html>

    案例4:位置偏移

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <style>
    7.       *{
    8.            margin: 0;
    9.            padding: 0;
    10.       }
    11.        .box{
    12.            width: 200px;
    13.            height: 200px;
    14.            background-color: orange;
    15.       }
    16.        .parent_box{
    17.             width: 800px;
    18.             height: 500px;
    19.             margin: 200px auto;
    20.             border: 1px solid rebeccapurple;
    21.       }
    22.    style>
    23. head>
    24. <body>
    25. <button class="btn1">offsetbutton>
    26. <div class="parent_box">
    27.    <div class="box">div>
    28. div>
    29. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js">script>
    30. <script>
    31.    var $offset=$(".box").offset();
    32.    var $left=$offset.left;
    33.    var $top=$offset.top;
    34.    console.log("$offset","top:"+$top+" left:"+$left)
    35.    var $position=$(".box").position();
    36.    var $left=$position.left;
    37.    var $top=$position.top;
    38.    console.log("$position","top:"+$top+" left:"+$left);
    39.    $(".btn1").click(function () {
    40.        $(".box").offset({left:50,top:50})
    41.   });
    42. script>
    43. body>
    44. html>

    5、jQuery的动画

    5.1、基本方法

    /*
    //基本
      show([s,[e],[fn]])   显示元素
      hide([s,[e],[fn]])   隐藏元素
    ​
    //滑动
      slideDown([s],[e],[fn])  向下滑动 
      slideUp([s,[e],[fn]])    向上滑动
    ​
    //淡入淡出
      fadeIn([s],[e],[fn])     淡入
      fadeOut([s],[e],[fn])    淡出
      fadeTo([[s],opacity,[e],[fn]])  让元素的透明度调整到指定数值
    ​
    //自定义
      animate(p,[s],[e],[fn])   自定义动画 
      stop([c],[j])             暂停上一个动画效果,开始当前触发的动画效果
      
    */

    案例:动画显示

    1. html>
    2. <html lang="en">
    3. <head>
    4.    <meta charset="UTF-8">
    5.    <title>Titletitle>
    6.    <style>
    7.        .c1{
    8.            width: 250px;
    9.            height: 250px;
    10.            background-color: black;
    11.       }
    12.        .hide{
    13.            display: none;
    14.       }
    15.    style>
    16.    <script src="jquery3.6.js">script>
    17. head>
    18. <body>
    19. <p>
    20.    <button class="show01">显示button>
    21.    <button class="hide01">隐藏button>
    22. p>
    23. <p>
    24.    <button class="show02">显示button>
    25.    <button class="hide02">隐藏button>
    26. p>
    27. <p>
    28.    <button class="show03">显示button>
    29.    <button class="hide03">隐藏button>
    30. p>
    31. <p>
    32.    <button class="show04">显示button>
    33.    <button class="hide04">隐藏button>
    34. p>
    35. <hr>
    36. <div class="c1">div>
    37. <script>
    38.    // 自己实现的隐藏与显示
    39.    $(".show01").click(function () {
    40.        $(".c1").removeClass("hide")
    41.   });
    42.    $(".hide01").click(function () {
    43.        $(".c1").addClass("hide")
    44.   });
    45.    // (1) show与hide方法
    46.    $(".show02").click(function () {
    47.        $(".c1").show(1000,function () {
    48.            alert("显示成功")
    49.       });
    50.   });
    51.    $(".hide02").click(function () {
    52.        $(".c1").hide(1000,function () {
    53.            alert("隐藏成功")
    54.       })
    55.   });
    56.     // (2) slideDown与slideUp
    57.     $(".show03").click(function () {
    58.        $(".c1").slideDown(1000,function () {
    59.            alert("显示成功")
    60.       });
    61.     });
    62.     $(".hide03").click(function () {
    63.        $(".c1").slideUp(1000,function () {
    64.            alert("隐藏成功")
    65.       })
    66.   });
    67.      // (3) fadeIn与fadeOut
    68.     $(".show04").click(function () {
    69.        $(".c1").fadeIn(1000,function () {
    70.            alert("显示成功")
    71.       });
    72.     });
    73.     $(".hide04").click(function () {
    74.        $(".c1").fadeOut(1000,function () {
    75.            alert("隐藏成功")
    76.       })
    77.   });
    78. script>
    79. body>
    80. html>

    5.2、自定义动画

    $(".box").animate(动画最终效果,动画完成的时间,动画完成以后的回调函数)
    1. $(".animate").click(function () {
    2.        $(".c1").animate({
    3.            "border-radius":"50%",
    4.            "top":340,
    5.            "left":200
    6.       },1000,function () {
    7.            $(".c1").animate({
    8.                "border-radius":"0",
    9.                "top":240,
    10.                "left":120
    11.           },1000,function () {
    12.                $(".animate").trigger("click")
    13.           })
    14.       })
    15.        
    16.   })

    6、扩展方法 (插件机制)

    • jQuery.extend(object)

    扩展jQuery对象本身。
    ​
    用来在jQuery命名空间上增加新函数。 
    ​
    在jQuery命名空间上增加两个函数:
    
    1. <script>
    2.    jQuery.extend({
    3.      min: function(a, b) { return a < b ? a : b; },
    4.      max: function(a, b) { return a > b ? a : b; }
    5. });
    6.    jQuery.min(2,3); // => 2
    7.    jQuery.max(4,5); // => 5
    8. script>

     

    • jQuery.fn.extend(object)

    扩展 jQuery 元素集来提供新的方法(通常用来制作插件)
    ​
    增加两个插件方法:
    
    1. <body>
    2. <input type="checkbox">
    3. <input type="checkbox">
    4. <input type="checkbox">
    5. <script src="jquery.min.js">script>
    6. <script>
    7.    jQuery.fn.extend({
    8.      check: function() {
    9.         $(this).attr("checked",true);
    10.     },
    11.      uncheck: function() {
    12.         $(this).attr("checked",false);
    13.     }
    14.   });
    15.    $(":checkbox").check()
    16. script>
    17. body>

  • 相关阅读:
    面试精选:3、史上最详细的Linux精选面试题(二)
    redis--重要知识点扫盲
    使用 tensorboard 可视化 kears训练结果
    【完美云曦篇】新预告,云曦遭魔改被抓,石昊首秀九天劫光,反杀战王
    从Matrix-ResourceCanary看内存快照生成-ForkAnalyseProcessor(1)
    deepwalk&node2vec 代码实战
    认识ICMP协议 —— ping命令的作用过程
    概率论的案例分析[1]
    交叉熵与对数似然分析
    电机剧烈振动的原因及解决办法(附电机振动监测方案)
  • 原文地址:https://blog.csdn.net/wojiubugaosuni12/article/details/134562340