一 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. Linux如何关机与关机命令祥解

    Linux关机命令祥解 1.直接关电源 2.init 0 3.telinit 0 4.shutdown -h now 5.halt6.poweroff 1.shutdown shutdown命令安全地 ...

  2. 设计模式之代理模式(php实现)

    github地址:https://github.com/ZQCard/design_pattern /** * 在代理模式中,我们创建具有现有对象的对象,以便向外界提供功能接口. * 1.Window ...

  3. unity, inspector debug

    以前经常因为脚本中private变量不在inspector界面中显示,不方便观察其值的变化,所以本该用private的用了public. 今天发现,原来inspector有个选项,如图,平常勾选的是N ...

  4. Eclipse RCP应用开发(概念)

    学习Eclipse RCP应用开发,对其中一些相关的概念需要了解. 让我们在讲解概念前先思考两个问题. 问题一.什么是Eclipse 大部分同学会回答eclipse是IBM公司开发的java集成开发环 ...

  5. netty的理解

    netty作为nio应用的典范,在很多设计方面都值得我们在程序开发中学习. 1.事件驱动,三种事件的传播机制.一种是在channel上触发,一种是在pipeline上触发,一种是在context上触发 ...

  6. java - day07 - PrimeNum

    判断质数 package day06; import java.util.Scanner; //验证质数 public class primeNum { public static void main ...

  7. 学习笔记 - Unity是如何将你的项目发布到如此多的平台的?

    很多Unity的开发者是不是都会觉得Unity能把项目导出发布到那么多不同的平台上运行是件很牛X的事情?那么你有没有想过Unity是如何做到的呢?本文就来大体的聊一聊Unity做的这件神奇的事情. 概 ...

  8. GoWeb编程之多路复用

    GoWeb编程多路复用 在web编程中,比如我们要一个Url对应一个处理函数,或者一个页面对应一个静态文件,这些都需要进行处理,这个时候就是我们多路复用派上用场了. package main impo ...

  9. 1211日课后shell总结

      1211shell   作者:高波 归档:学习笔记 2017年12月11日13:10:56 快捷键: Ctrl + 1 标题1 Ctrl + 2 标题2 Ctrl + 3 标题3 Ctrl + 4 ...

  10. php zend studio 如何导入已经存在的项目

    点击 左上的   file->import ->General->在选择第二个[  Exissting ....]