zoukankan      html  css  js  c++  java
  • jQuery中 :first、:first-child 和 :first-of-type 之间的不同

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
    $("button").click(function(){
    var btn = $(this).text();
    $("p").css("background-color","white");
    $("p" + btn).css("background-color","yellow");
    });
    });
    </script>
    </head>
    <body>
    <button>:first</button>
    <button>:first-child</button>
    <button>:first-of-type</button><br><br>
    <p>body 中第一个段落。</p>

    <div style="border:1px solid;">
    <p>div 中第一个段落,是 div 的第一个子元素。</p>
    <p>div 中的最后一个段落,是 div 的最后一个子元素。</p>
    </div><br>

    <div style="border:1px solid;">
    <span>这是一个 span 元素,是 div 中的第一个子元素。</span>
    <p>另一个 div 中第一个段落,是 div 中的第二个子元素。</p>
    <p>另一个 div 中的最后一个段落, 是 div 中的第三个子元素。</p>
    <span>这是一个 span 元素,是 div 中的最后一个子元素。</span>
    </div><br>

    <div style="border:1px solid">
    <p>另一个 div 中第一个段落,是 div 中的第一个子元素。</p>
    <p>另一个 div 中的最后一个段落, 是 div 中的最后一个子元素。</p>
    </div>

    <p>body 中最后一个段落。</p>

    </body>
    </html>

  • 相关阅读:
    第11组 Beta版本演示
    第11组 Beta冲刺(5/5)
    第11组 Beta冲刺(4/5)
    第11组 Beta冲刺(3/5)
    第11组 Beta冲刺(2/5)
    第11组 Beta冲刺(1/5)
    第11组 Alpha冲刺(2/6)
    第11组 Alpha冲刺(1/6)
    第11组 团队Git现场编程实战
    团队项目-需求分析报告
  • 原文地址:https://www.cnblogs.com/fireporsche/p/6395752.html
Copyright © 2011-2022 走看看