欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery中children()方法用法實例

 更新時間:2015年01月07日 09:31:27   投稿:shichen2014  
這篇文章主要介紹了jQuery中children()方法用法,實例分析了children()方法的功能、定義及過濾所匹配子元素的使用技巧,需要的朋友可以參考下

本文實例講述了jQuery中children()方法用法。分享給大家供大家參考。具體分析如下:

此方法取得一個包含匹配元素集合中每一個元素的所有子元素的元素集合。
可以通過可選的表達式來過濾所匹配的子元素。

注意:find()將查找所所有子元素,而children()只獲取一級子元素。

語法結(jié)構(gòu):

復(fù)制代碼 代碼如下:
$(selector).children(expr)

參數(shù)列表:

參數(shù) 描述
expr 可選。用以過濾子元素的表達式

實例代碼:

實例一:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>children()函數(shù)-腳本之家</title>
<style type="text/css">
p{
  border:1px solid blue
}
.children{
  border:1px solid green;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".father").children().css("height","100px");
})
</script>
</head>
<body>
<div class="father">
<div class="children">
   <p>我是孫子p</p>
</div>
<p>我是兒子p</p>
</div>
<p>我是兄弟p</p>
</body>
</html>

此方法只匹配一級子元素。

實例二:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>children()-腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".father").children(".children").css("color","red");
})
</script> 
</head>
<body>
<div class="father">
<div class="children">
   <p>我是孫子p</p>
</div>
<p>我是兒子p</p>
</div>
<p>我是兄弟p</p>
</body>
</html>

以上代碼可以將處class屬性值為children的子元素中的字體顏色設(shè)置為紅色。

相關(guān)文章

最新評論