最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

.children()

.children( [ selector ] ) 返回: jQuery

描述: 獲得每個匹配元素集合元素的子元素,選擇性篩選的選擇器。

  • version added: 1.0.children( [ selector ] )

    selector一個用于匹配元素的選擇器字符串。

鑒于一個jQuery對象,表示一個DOM元素的集合,.children()方法允許我們通過在DOM樹中對這些元素的直接子元素進行搜索,并且構(gòu)造一個新的匹配元素的jQuery對象。.find().children()方法是相似的,但后者只是針對向下一個級別的DOM樹。還要注意的是最喜歡的jQuery方法,.children()不返回文本節(jié)點;讓所有子元素包括使用文字和注釋節(jié)點,建議使用.contents()。

該方法選擇性地接受同一類型選擇器表達式,我們可以傳遞給$()函數(shù)。如果選擇供應(yīng),將被過濾的元素通過測試它們是否匹配。

考慮一個面頁中簡單的列表:

<ul class="level-1">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a">A</li>
      <li class="item-b">B
        <ul class="level-3">
          <li class="item-1">1</li>
          <li class="item-2">2</li>
          <li class="item-3">3</li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii">III</li>
</ul>

如果我們在2級列表開始,我們可以找到它的子元素:

$('ul.level-2').children().css('background-color', 'red');

此調(diào)用的結(jié)果是一個落后項目A,B和C紅底,由于我們沒有提供一個選擇的表達,所有的子元素都返回的jQuery對象的一部分。如果我們提供的人,只有三者匹配項目將包括在內(nèi)。

Examples:

Example: Find all children of the clicked element.

<!DOCTYPE html>
<html>
<head>
  <style>
  body { font-size:16px; font-weight:bolder; }
  div { width:130px; height:82px; margin:10px; float:left;
        border:1px solid blue; padding:4px; }
  #container { width:auto; height:105px; margin:0; float:none;
        border:none; }
  .hilite { border-color:red; }
  #results { display:block; color:red; }
  p { margin:10px; border:1px solid transparent; }
  span { color:blue; border:1px solid transparent; }
  input { width:100px; }
  em { border:1px solid transparent; }
  a { border:1px solid transparent; }
  b { border:1px solid transparent; }
  button { border:1px solid transparent; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <div id="container">

    <div>
      <p>This <span>is the <em>way</em> we</span> 
      write <em>the</em> demo,</p>

    </div>
    <div>
      <a href="#"><b>w</b>rit<b>e</b></a> the <span>demo,</span> <button>write 
      the</button> demo,
    </div>

    <div>
      This <span>the way we <em>write</em> the <em>demo</em> so</span>

      <input type="text" value="early" /> in
    </div>
    <p>
      <span>t</span>he <span>m</span>orning.
      <span id="results">Found <span>0</span> children in <span>TAG</span>.</span>

    </p>
  </div>
<script>

    $("#container").click(function (e) {
      $("*").removeClass("hilite");
      var $kids = $(e.target).children();
      var len = $kids.addClass("hilite").length;

      $("#results span:first").text(len);
      $("#results span:last").text(e.target.tagName);

      e.preventDefault();
      return false;
    });
</script>

</body>
</html>

Demo:

Example: Find all children of each div.

<!DOCTYPE html>
<html>
<head>
  <style>
  body { font-size:16px; font-weight:bolder; }
  span { color:blue; }
  p { margin:5px 0; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p>Hello (this is a paragraph)</p>

  <div><span>Hello Again (this span is a child of the a div)</span></div>
  <p>And <span>Again</span> (in another paragraph)</p>

  <div>And One Last <span>Time</span> (most text directly in a div)</div>
<script>$("div").children().css("border-bottom", "3px double red");</script>

</body>
</html>

Demo:

Example: Find all children with a class "selected" of each div.

<!DOCTYPE html>
<html>
<head>
  <style>

  body { font-size:16px; font-weight:bolder; }
  p { margin:5px 0; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <div>
    <span>Hello</span>
    <p class="selected">Hello Again</p>
    <div class="selected">And Again</div>

    <p>And One Last Time</p>
  </div>
<script>$("div").children(".selected").css("color", "blue");</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版腳本之家整理、修訂 (2011年6月)
阳原县| 吴忠市| 西畴县| 措勤县| 淄博市| 贵溪市| 施甸县| 灵丘县| 日照市| 丹巴县| 繁昌县| 仙桃市| 高青县| 旅游| 通化市| 西华县| 凌云县| 仁怀市| 蒲城县| 始兴县| 广灵县| 泰顺县| 且末县| 福贡县| 凤阳县| 新兴县| 浦东新区| 赤峰市| 治县。| 德令哈市| 宜川县| 德惠市| 尤溪县| 东乡族自治县| 定结县| 宣恩县| 牟定县| 巴林右旗| 法库县| 讷河市| 高密市|