• jQuery常用子元素过滤选择器


    !DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>常用子元素过滤选择器</title>
        <script src="scripts/jquery-3.1.1.js" type="text/javascript"></script>
        <script type="text/javascript">
            //:first-child 当前元素是父亲的第一个儿子
            //这个排行不包括文本
            $(function(){
                /*alert($("li:first-child").length);
                alert($("li:first-child").text());
                //first-of-type 是当前元素父亲的当前类型儿子中的一个
                alert($("li:first-of-type").length);*/
                //:only-child 是父亲唯一的儿子
                //alert($("span:only-child").length);//1
                //only-of-type 是父亲当前类型的唯一的儿子
                //alert($("span:only-of-type").length)
                //nth-child(index/odd/even)
                //是父亲的奇数个孩子   下标从1开始
                alert($("ul li:nth-child(odd)").length);
            });
    
        </script>
    </head>
    <body>
    <div>
        <div id="div1">
            <h3 class="one">手机品牌</h3>
            <ul class="one">
                <span>test11</span>
                <li class="one">苹果</li>
                <li class="one">华为</li>
                <li class="one">vivo</li>
            </ul>
            <p>
                <span>test22</span>
            </p>
            <h3>电脑品牌</h3>
            <ul class="one">
                <span>test</span>
                <li>联想</li>
                <li>苹果</li>
                <li hidden="true">戴尔</li>
                <li hidden="true">东芝</li>
                <span>test</span>
            </ul>
        </div>
        <div>
            <h3>销量排行</h3>
            <ol>
                <li>vivo</li>
                <li>苹果</li>
                <li>华为</li>
            </ol>
        </div>
        hahafinish
    </div>
    </body>
    </html>
    

      

  • 相关阅读:
    ubuntu nfs server config
    增加虚拟机ubuntu的硬盘
    MD5算法
    MySQL错误ERROR 1366 (HY000): Incorrect string value..
    SQLPro Studio链接本地MYSQL
    mysql修改root密码
    jdk7 for Mac
    mysql is stop 点击start启动不了,卸载重装
    Mac版Intellij IDEA弹窗报this license XXXXXXXX has been cancelled
    Python 环境搭建
  • 原文地址:https://www.cnblogs.com/john568300/p/6420967.html
Copyright © 2020-2023  润新知