• jquery选择器筛选器


    jQuery对象

    Query 对象就是通过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()     

     参考:http://jquery.cuishifeng.cn/

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

    3.1   选择器

    3.1.1 基本选择器      

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

    3.1.2 层级选择器   

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

    3.1.3 基本筛选器  

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

    3.1.4 属性选择器

    1
    $('[id="div1"]')   $('["alex="sb"][id]')

    3.1.5 表单选择器      

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

    3.1.6 表单属性选择器

        :enabled
        :disabled
        :checked
        :selected
    <body>
    
    <form>
        <input type="checkbox" value="123" checked>
        <input type="checkbox" value="456" checked>
    
    
      <select>
          <option value="1">Flowers</option>
          <option value="2" selected="selected">Gardens</option>
          <option value="3" selected="selected">Trees</option>
          <option value="3" selected="selected">Trees</option>
      </select>
    </form>
    
    
    <script src="jquery.min.js"></script>
    <script>
        // console.log($("input:checked").length);     // 2
    
        // console.log($("option:selected").length);   // 只能默认选中一个,所以只能lenth:1
    
        $("input:checked").each(function(){
    
            console.log($(this).val())
        })
    
    </script>
    
    
    </body>
    View Code

    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() 查找所有兄弟标签: $("div").siblings()
    查找父标签: $(".test").parent() $(".test").parents()
    $(".test").parentUntil()
    复制代码
  • 相关阅读:
    sqlserver 游标格式 东师理想
    java流下载 东师理想
    列出所有K个元素的子集2013年1月26日
    你刚才在淘宝上买了一件东西【技术普及贴】(转载)
    递归统计项目中的非空白代码行数
    算法(数据结构)每天一题 2013年1月21日
    《TCP/IP详解卷1》学习小结(二)Internet Protocol
    产生所有排列字典顺序2013年1月23日
    产生所有排列旋转法2013年1月22日
    《TCP/IP详解卷1》学习小结(三)ARP协议与RARP协议
  • 原文地址:https://www.cnblogs.com/pythonclass/p/7656037.html
Copyright © 2020-2023  润新知