一 iQuery是什么

jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team

jQuery是继prototype之后又一个优秀的Javascript框架。其宗旨是——WRITE LESS,DO MORE!

它是轻量级的js库(压缩后只有21k) ,这是其它的js库所不及的,它兼容CSS3,还兼容各种浏览器

jQuery是一个快速的,简洁的javaScript库,使用户能更方便地处理HTMLdocuments、events、实现动画效果,并且方便地为网站提供AJAX交互。

jQuery还有一个比较大的优势是,它的文档说明很全,而且各种应用也说得很详细,同时还有许多成熟的插件可供选择。

二 什么是jQuery对象?

jQuery 对象就是通过jQuery包装DOM对象后产生的对象。jQuery 对象是 jQuery 独有的. 如果一个对象是 jQuery 对象, 那么它就可以使用 jQuery 里的方法: $(“#test”).html();

$("#test").html()          //意思是指:获取ID为test的元素内的html代码。其中html()是jQuery里的方法       // 这段代码等同于用DOM实现代码: document.getElementById(" test ").innerHTML;       //虽然jQuery对象是包装DOM对象后产生的,但是jQuery无法使用DOM对象的任何方法,同理DOM对象也不能使用jQuery里的方法.乱使用会报错      //约定:如果获取的是 jQuery 对象, 那么要在变量前面加上$. var $variable = jQuery 对象var variable = DOM 对象$variable[0]:jquery对象转为dom对象      $("#msg").html(); $("#msg")[0].innerHTML

jquery的基础语法:$(selector).action()

使用时到官网下载保存(打开后按Ctrl+s可以保存),放到项目路径下引入

三 寻找元素(选择器和筛选器)

3.1   选择器

3.1.1 基本选择器

$("*")  $("#id")   $(".class")  $("element")  $(".class,p,div")

3.1.2 层级选择器

$(".outer div")  $(".outer>div")   $(".outer+div")  $(".outer~div")

3.1.3 基本筛选器

$("li:first")  $("li:eq(2)")  $("li:even") $("li:gt(1)")

3.1.4 属性选择器

$('[id="div1"]')

3.1.5 表单选择器

$("[type='text']")----->$(":text")         注意只适用于input标签  : $("input:checked")

实例之左侧菜单

<!DOCTYPE html><html lang="en"><head>   <meta charset="UTF-8">   <title>left_menu</title>

   <style>         .menu{             height: 500px;             width: 30%;             background-color: gainsboro;             float: left;         }         .content{             height: 500px;             width: 70%;             background-color: rebeccapurple;             float: left;         }        .title{            line-height: 50px;            background-color: #425a66;            color: forestgreen;}        .hide{            display: none;        }   </style></head><body>

<div class="outer">   <div class="menu">       <div class="item">           <div class="title">菜单一</div>           <div class="con">               <div>111</div>               <div>111</div>               <div>111</div>           </div>       </div>       <div class="item">           <div class="title">菜单二</div>           <div class="con hide">               <div>111</div>               <div>111</div>               <div>111</div>           </div>       </div>       <div class="item">           <div class="title">菜单三</div>           <div class="con hide">               <div>111</div>               <div>111</div>               <div>111</div>           </div>       </div>

   </div>   <div class="content"></div>

</div><script src="jquery-3.2.1.js"></script><script>          $(".item .title").click(function () {               $(this).next().removeClass("hide").parent().siblings().children(".con").addClass("hide");

//                $(this).next().removeClass("hide");//                $(this).parent().siblings().children(".con").addClass("hide");          })</script></body></html>

实例之tab切换

<!DOCTYPE html><html lang="en"><head>   <meta charset="UTF-8">   <title>tab</title>   <script src="jquery-3.3.1.min.js"></script>   <script>          function tab(self){              var index=$(self).attr("xxx");              $("#"+index).removeClass("hide").siblings().addClass("hide");              $(self).addClass("current").siblings().removeClass("current");

          }   </script>   <style>       *{           margin: 0px;           padding: 0px;       }       .tab_outer{           margin: 0px auto;           width: 60%;       }       .menu{           background-color: #cccccc;           /*border: 1px solid red;*/           line-height: 40px;       }       .menu li{           display: inline-block;       }       .menu a{           border-right: 1px solid red;           padding: 11px;       }       .content{           background-color: tan;           border: 1px solid green;           height: 300px;       }       .hide{           display: none;       }

       .current{           background-color: darkgray;           color: yellow;           border-top: solid 2px rebeccapurple;       }   </style></head><body>     <div class="tab_outer">         <ul class="menu">             <li xxx="c1" class="current" onclick="tab(this);">菜单一</li>             <li xxx="c2" onclick="tab(this);">菜单二</li>             <li xxx="c3" onclick="tab(this);">菜单三</li>         </ul>         <div class="content">             <div id="c1">内容一</div>             <div id="c2" class="hide">内容二</div>             <div id="c3" class="hide">内容三</div>         </div>

     </div></body></html>

3.2 筛选器

3.2.1  过滤筛选器

$("li").eq(2)  $("li").first()  $("ul li").hasclass("test")

3.2.2  查找筛选器

$("div").children(".test")     $("div").find(".test")                              $(".test").next()    $(".test").nextAll()    $(".test").nextUntil()                          $("div").prev()  $("div").prevAll()  $("div").prevUntil()                      $(".test").parent()  $(".test").parents()  $(".test").parentUntil() $("div").siblings()

四 操作元素(属性,css,文档处理)

4.1 属性操作

--------------------------属性$("").attr();$("").removeAttr();$("").prop();$("").removeProp();--------------------------CSS类$("").addClass(class|fn)$("").removeClass([class|fn])--------------------------HTML代码/文本/值$("").html([val|fn])$("").text([val|fn])$("").val([val|fn|arr])---------------------------$("").css("color","red")

jQuery循环的两种方式

jquery循环的两种方式方式一li=[10,20,30,40]dic={name:"yuan",sex:"male"}$.each(li,function(i,x){    console.log(i,x)})

方式二$("tr").each(function(){   console.log($(this).html())})

实例之全反选

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>Title</title>  <script src="jquery-3.3.1.min.js"></script>  <script>           function selectall(){               $("table :checkbox").prop("checked",true)           }           function cancel(){               $("table :checkbox").prop("checked",false)           }           function reverse(){               $("table :checkbox").each(function(){                   $(this).prop("checked",!$(this).prop("checked"));               });           }  </script></head><body>

   <button onclick="selectall();">全选</button>   <button onclick="cancel();">取消</button>   <button onclick="reverse();">反选</button>

   <table border="1">       <tr>           <td><input type="checkbox"></td>           <td>111</td>       </tr>       <tr>           <td><input type="checkbox"></td>           <td>222</td>       </tr>       <tr>           <td><input type="checkbox"></td>           <td>333</td>       </tr>       <tr>           <td><input type="checkbox"></td>           <td>444</td>       </tr>   </table></body></html>

实例之模态对话框

<!DOCTYPE html><html lang="en"><head>   <meta charset="UTF-8">   <title>Title</title>   <style>       .back{           background-color: rebeccapurple;           height: 2000px;       }

       .shade{           position: fixed;           top: 0;           bottom: 0;           left:0;           right: 0;           background-color: coral;           opacity: 0.4;       }

       .hide{           display: none;       }

       .models{           position: fixed;           top: 50%;           left: 50%;           margin-left: -100px;           margin-top: -100px;           height: 200px;           width: 200px;           background-color: gold;

       }   </style></head><body><div class="back">   <input id="ID1" type="button" value="click" onclick="action1(this)"></div>

<div class="shade hide"></div><div class="models hide">   <input id="ID2" type="button" value="cancel" onclick="action2(this)"></div>

<script src="jquery-3.3.1.min.js"></script><script>

   function action1(self){       $(self).parent().siblings().removeClass("hide");

   }   function action2(self){       //$(self).parent().parent().children(".models,.shade").addClass("hide")   $(self).parent().addClass("hide").prev().addClass("hide")   }</script></body></html>

4.2 文档处理

//创建一个标签对象   $("<p>")//内部插入   $("").append(content|fn)      ----->$("p").append("<b>Hello</b>");   $("").appendTo(content)       ----->$("p").appendTo("div");   $("").prepend(content|fn)     ----->$("p").prepend("<b>Hello</b>");   $("").prependTo(content)      ----->$("p").prependTo("#foo");//外部插入   $("").after(content|fn)       ----->$("p").after("<b>Hello</b>");   $("").before(content|fn)      ----->$("p").before("<b>Hello</b>");   $("").insertAfter(content)    ----->$("p").insertAfter("#foo");   $("").insertBefore(content)   ----->$("p").insertBefore("#foo");//替换   $("").replaceWith(content|fn) ----->$("p").replaceWith("<b>Paragraph. </b>");//删除   $("").empty()   $("").remove([expr])//复制   $("").clone([Even[,deepEven]])

4.3 css操作

CSS       $("").css(name|pro|[,val|fn])   位置       $("").offset([coordinates])       $("").position()       $("").scrollTop([val])       $("").scrollLeft([val])   尺寸       $("").height([val|fn])       $("").width([val|fn])       $("").innerHeight()       $("").innerWidth()       $("").outerHeight([soptions])       $("").outerWidth([options])

实例返回顶部

<!DOCTYPE html><html lang="en"><head>   <meta charset="UTF-8">   <title>Title</title>   <script src="js/jquery-2.2.3.js"></script>   <script>

         window.onscroll=function(){

             var current=$(window).scrollTop();             console.log(current)             if (current>100){

                 $(".returnTop").removeClass("hide")             }             else {             $(".returnTop").addClass("hide")         }         }

          function returnTop(){//               $(".div1").scrollTop(0);

              $(window).scrollTop(0)          }

   </script>   <style>       body{           margin: 0px;       }       .returnTop{           height: 60px;           width: 100px;           background-color: darkgray;           position: fixed;           right: 0;           bottom: 0;           color: greenyellow;           line-height: 60px;           text-align: center;       }       .div1{           background-color: orchid;           font-size: 5px;           overflow: auto;           width: 500px;       }       .div2{           background-color: darkcyan;       }       .div3{           background-color: aqua;       }       .div{           height: 300px;       }       .hide{           display: none;       }   </style></head><body>    <div class="div1 div">        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>        <p>hello</p>

    </div>    <div class="div2 div"></div>    <div class="div3 div"></div>    <div class="returnTop hide" onclick="returnTop();">返回顶部</div></body></html>

识别图中二维码,领取python全套视频资料

前端框架之jQuery的更多相关文章

  1. 前端框架之jQuery(二)----轮播图,放大镜

    事件 页面载入   ready(fn)  //当DOM载入就绪可以查询及操纵时绑定一个要执行的函数.   $(document).ready(function(){}) -----------> ...

  2. jQuery后续和 前端框架Bootstrap

    目录 一.jQuery后续 1. 动画效果 (1)自定义点赞动画实例 2. jQuery的自带方法 (1)each (类似for循环) (2)data() (存放隐形的数据) 二.前端框架之Boots ...

  3. jQuery操作标签,jQuery事件操作,jQuery动画效果,前端框架

    jQuery操作标签 jQuery代码查找标签绑定的变量名推荐使用 $xxxEle 样式类操作 addClass();// 添加指定的CSS类名. removeClass();// 移除指定的CSS类 ...

  4. 前端框架 EasyUI (0) 重新温习(序言)

    几年前,参与过一个项目.那算是一个小型的信息管理系统,BS 结构的,前端用的是基于 jQuery 的 EasyUI 框架. 我进 Team 的时候,项目已经进入开发阶段半个多月了.听说整个项目的框架是 ...

  5. 10大H5前端框架

    作为一名做为在前端死缠烂打6年并且懒到不行的攻城士,这几年我还是阅过很多同门从知名到很知名的各种前端框架,本来想拿15-20个框架来分享一下,但在跟几个前辈讨教写文章的技巧时果断被无情的打击了,所以这 ...

  6. Web前端框架与类库的思考

    说起前端框架,我也是醉了.现在去面试或者和同行聊天,动不动就这个框架碉堡了,那个框架好犀利. 当然不是贬低框架,只是有一种杀鸡焉用牛刀的感觉.网站技术是为业务而存在的,除此毫无意义,框架也是一样.在技 ...

  7. React 还是 Vue: 你应该选择哪一个Web前端框架?

    学还是要学的,用的多了,也就有更多的认识了,开发中遇到选择的时候也就简单起来了. 本文作者也做了总结: 如果你喜欢用(或希望能够用)模板搭建应用,请使用Vue    如果你喜欢简单和“能用就行”的东西 ...

  8. CI框架如何在主目录application目录之外使用uploadify上传插件和bootstrap前端框架:

    19:29 2016/3/10CI框架如何在主目录application目录之外使用uploadify上传插件和bootstrap前端框架:项目主路径:F:\wamp\www\graduationPr ...

  9. Web前端框架汇总

    在做web开发的时候难免遇到一个问题,那就是,选择什么样的框架.下面把前端的框架简单的列一下. 1.flex Apache基金会今天发布了Flex 4.8版本,这是Adobe将Flex捐献给Apach ...

随机推荐

  1. TCP/IP --概述

    分层 网络协议通常分不同层次进行开发,每一层分别负责不同的通信功能.一个协议族,比如T C P / I P,是一组不同层次上的多个协议的组合.T C P / I P通常被认为是一个四层协议系统.,如图 ...

  2. go项目布局(摘录)

    go的项目结构布局 或 包结构布局 这一块大家似乎还在摸索吧, 常用的应该还是类似于java的mvc布局, 但网上也有不同的布局方式,查阅github上的一些源码,也有大量的采用. 我把自己碰到的资料 ...

  3. redis内存分析(转)

    背景 线上经常遇到用户想知道自己 Redis 实例中数据的内存分布情况.为了不影响线上实例的使用,我们一般会采用 bgsave 生成 dump.rdb 文件,再结合 redis-rdb-tools 和 ...

  4. Xamarin for VS 3.11.1594 Stable版免费完整破解补丁

    Xamarin for VS 3.11.1594 Stable版免费完整破解补丁 此版本只能用于3.11.1594版本破解, 其他版本可能会有错误. Android和IOS完整支持,不像某些破解只支持 ...

  5. 时间序列 R 读书笔记 04 Forecasting: principles and practice

    本章開始学习<Forecasting: principles and practice> 1 getting started 1.1 事件的可预言性 一个时间能不能被预言主要取决于以下三点 ...

  6. Vuex 2 入门与提高。

    从计数器开始 让我们从一个简单的计数器,开始进入Vuex 的世界: 计数器应用的数据模型很简单:使用一个counter属性来表示计数器的 当前值就够了. 在Vue实例的created钩子 中,应用启动 ...

  7. MacOS 自带文件编码格式转换工具

    [命令功能]iconv 是Linux操作系统用于将文本编码格式从一种转外另外一种的工具命令.[使用方法] iconv [OPTION...] [-f ENCODING] [-t ENCODING] [ ...

  8. 什么时候触发MinorGC?什么时候触发FullGC?

    触发MinorGC(Young GC) 虚拟机在进行minorGC之前会判断老年代最大的可用连续空间是否大于新生代的所有对象总空间 1.如果大于的话,直接执行minorGC 2.如果小于,判断是否开启 ...

  9. Python运行机制(转)

    From:https://blog.csdn.net/jeff_liu_sky_/article/details/52097060 https://stackoverflow.com/question ...

  10. Java Web -- Servlet(1) 必备知识

    学习Java WEB开发必备的基本概念: 1.WEB 本意是蜘蛛网和网的意思.在网页设计中我们称为网页的意思. 现广泛译作网络.互联网等技术领域.表现为三种形式,即超文本(hypertext).超媒体 ...