• jQuery初识


    jQuery:

    是一个轻量级的、兼容多浏览器的JavaScript库。

    使用户能够更方便地处理HTML Document、Events、实现动画效果、方便地进行Ajax交互,能够极大地简化JavaScript编程。它的宗旨就是:“Write less, do more.“

    jQuery内容:
    
    基本选择器 :
        id  	  $('#id')
        标签       $('tagName')
     class选择器 	$('.className')
        配合使用: $('div.cl')   // 找到有c1 class类的div标签
     所有元素 	   $('*')   
     组合选择器    $("#id, .className, tagName")
        
    层级选择器:
    $("x y");// x的所有后代y(子子孙孙)
    $("x > y");// x的所有儿子y(儿子)
    $("x + y")// 找到所有紧挨在x后面的y
    $("x ~ y")// x之后所有的兄弟y
    
    筛选器:(以索引值为准)
    :first // 第一个
    :last // 最后一个
    :eq(index)// 索引等于index的那个元素
    :even // 匹配所有索引值为偶数的元素,从 0 开始计数
    :odd // 匹配所有索引值为奇数的元素,从 0 开始计数
    :gt(index)// 匹配所有大于给定索引值的元素
    :lt(index)// 匹配所有小于给定索引值的元素
    :not(元素选择器)// 移除所有满足not条件的标签
    :has(元素选择器)// 选取所有包含一个或多个标签在其内的标签(指的是从后代元素找)
    
    属性选择器:
    [attribute]
    [attribute=value]// 属性等于
    [attribute!=value]// 属性不等于
    

    下载链接:jQuery官网

    中文文档:jQuery AP中文文档

    jQuery版本:
    1.x:兼容IE678,使用最为广泛的,官方只做BUG维护,功能不再新增。因此一般项目来说,使用1.x版本就可以了,最终版本:1.12.4 (2016年5月20日)
    2.x:不兼容IE678,很少有人使用,官方只做BUG维护,功能不再新增。如果不考虑兼容低版本的浏览器可以使用2.x,最终版本:2.2.4 (2016年5月20日)
    3.x:不兼容IE678,只支持最新的浏览器。需要注意的是很多老的jQuery插件不支持3.x版。目前该版本是官方主要更新维护的版本。
    维护IE678是一件让人头疼的事情,一般我们都会额外加载一个CSS和JS单独处理
    
    jQuery对象:
    
    jQuery对象就是通过jQuery包装DOM对象后产生的对象。jQuery对象是 jQuery独有的。如果一个对象是 jQuery对象,那么它就可以使用jQuery里的方法:例如$(“#i1”).html()。
    $("#i1").html()的意思是:获取id值为 i1的元素的html代码。其中 html()是jQuery里的方法
    
    jQuery对象是包装 DOM对象后产生的,但是 jQuery对象无法使用 DOM对象的任何方法,同理 DOM对象也没不能使用 jQuery里的方法。 
                          
    对象转换:                                                        
    var $variable = jQuery对像
    var variable = DOM对象
    $variable[0]//jQuery对象转成DOM对象  
                                                                                                
    JQuery基础语法:
    $(selector).action()
    

    $(selector).action()

    左表单实现:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="x-ua-compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>左表单</title>
        <style>
            .left {
                position: fixed;
                left:0;
                top:0;
                20% ;
                height: 100%;
                background-color: dimgray;
    
            }
            .right {
                 80%;
                height: 100%;
            }
            .menu {
                color:white;
            }
            .title {
                background-color: #5897fb;
                padding: 10px 15px;
                text-align: center;
            }
            .items {
                background-color: mediumorchid;
    
            }
            .item {
                padding: 5px 10px;
                border-bottom: 1px solid #5E5694 ;
            }
            .hide {
                display: none;
            }
        </style>
    </head>
    <body>
    <div class="left">
      <div class="menu">
        <div class="item">
          <div class="title">菜单一</div>
          <div class="items">
            <div class="item">111</div>
            <div class="item">222</div>
            <div class="item">333</div>
        </div>
        </div>
        <div class="item">
          <div class="title">菜单二</div>
          <div class="items hide">
          <div class="item">111</div>
          <div class="item">222</div>
          <div class="item">333</div>
        </div>
        </div>
        <div class="item">
          <div class="title">菜单三</div>
          <div class="items hide">
          <div class="item">111</div>
          <div class="item">222</div>
          <div class="item">333</div>
        </div>
        </div>
      </div>
    </div>
    <div class="right"></div>
    
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script>
        $(".title").click(function() {
            //链式操作,this-->当前的对象
            $(this).next().removeClass('hide').parent().siblings().find('.items').addClass('hide')
        })
    </script>
    </body>
    </html>
    
  • 相关阅读:
    DOS命令收集
    iis6配置支持.net4.0
    正则表达式限制文本框
    剖析XML(第一讲)
    DataTime.ToString("xx") 转换
    .net面试题大汇集
    django学习笔记(一)
    django学习笔记(一)
    django学习笔记(二)
    django学习笔记(二)
  • 原文地址:https://www.cnblogs.com/shaozheng/p/11891574.html
Copyright © 2020-2023  润新知