美文网首页
2 Jquery 的选择器

2 Jquery 的选择器

作者: 流光已至 | 来源:发表于2018-08-02 20:43 被阅读0次

1 id选择器

2 元素选择器

跳出循环使用: return false;

3 类选择器

多种选择器可以叠加,用逗号分隔即可。

4 层次选择器

中间空格隔开,在给定祖先元素下匹配所有的后代元素

中间 > 隔开,匹配所有的子元素,即不包括孙子元素

prev + next , 匹配所有紧接在prev元素后的next一个元素,中间不能隔有元素

prev~siblings, 匹配prev元素之后的所有的siblings(兄弟,同辈)元素,不包含该元素,并且是后面元素。

5 过滤选择器

: last 最后一个元素 :even 偶数元素 (从0开始) :odd 奇数元素

效果和相应的代码如下:

<script type="text/javascript">
  
    $(function(){
      
       $("tr:even").css({background:'yellow'})   // 后面为Json,可加多个    
    })
    
    
    function myclick(){
        
        $("tr:first").each(function(){
            
              alert($(this).html());
        
        })
    }
   
</script>
<style type="text/css">
    table{
       border-collapse: collapse  <!--将线变成单线 -->
    }
</style>
</head>
<body>
   <table border="1">
       <tr><td>李逵</td><td>30</td></tr>
       <tr><td>李鬼</td><td>28</td></tr>
        <tr><td>宋江</td><td>34</td></tr>
        <tr><td>花荣</td><td>29</td></tr>
   </table>
  <input value="点击" type="button" onclick="myclick()">
</body>
</html>

实现全选,与反选

// 全选
    function  checkAll(){
        
   /*     $("td input").each(function(){
           
           $(this).attr("checked","checked")
           
       }) */
       
       $("td input").attr("checked","checked");
    }
    
    function reverseCheck(){
        
        $("td input").each(function(){
            
            var checkState = $(this).attr("checked");
            
            if(checkState=='checked'){
                $(this).removeAttr("checked");
            }else{
                
                 $(this).attr("checked","checked")
            }
            
        })
        
        
    }

其余过滤选择器:tr:eq(1) 获取第一个tr元素,从0 开始
tr:gt(),tr:lt() 大于,小于index的元素

相关文章

  • jquery选择器书目录

    jquery选择器-基本选择器 jquery选择器-层级选择器 jquery选择器-基本过滤选择器 jquery选...

  • JQUERY一

    jQuery 元素选择器 jQuery 属性选择器 jQuery CSS 选择器 jQuery 事件 jQuery...

  • jQuser有选择器

    jQuery基本选择器 jQuery过滤选择器 jQuery层级选择器 jQuery筛选选择器(方法)

  • jQuery 基础

    jQuery jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样...

  • jQuery

    jQuery jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样...

  • 选择器

    jQuery 元素选择器 jQuery 属性选择器 jQuery CSS 选择器

  • jQuery笔记

    1. jQuery 介绍 2. jQuery 的基本使用 3. jQuery 选择器 4. jQuery 样式操...

  • JQuery基础知识

    jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样式 css操作...

  • jQuery选择器

    一、jQuery常用选择器 二、jQuery选择器优势 三、jQuery常用基本选择器 四、jQuery常用层次选...

  • jQuery选择器

    jQuery选择器 jQuery选择器完全继承了CSS的风格。学会使用选择器是学习jQuery的基础,jQuery...

网友评论

      本文标题:2 Jquery 的选择器

      本文链接:https://www.haomeiwen.com/subject/haqdvftx.html