jquery eq() get() css() lengh()

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
<script src=" http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"type="text/javascript"></script> 
<script type="text/javascript">
$(document).ready(function(){
//alert($("p").eq(0).html());//獲取第一個P中的內容,
//alert($("p").get(0).innerHTML);//獲取第一個P中的內容,This is just test
//alert($("p").eq(0).css("color"));//取得第一個p的CSS color屬性值 red
//alert($("p").get(0).css("color"));//這樣是取不到的,因爲get(num)返回的是個html對象
//alert($("p").get(0).style.color);//這樣可以取得html對象的color
//alert($($("p").get(0)).css("color"));//用$()將$("p").get(0)出來的html對象轉化成jquery對象,再用jquery的CSS方法
//alert($("p").length);//取得所有p的個數
//alert($("#ul_1 ul").length);//取得ul的個數,返回3

alert($("#ul_1 ul li").length);//取得ul內li的個數 返回12
})
</script>
 </head>
 <body>
  <p style="color:red"> This is just a test.</p> <p> So is this</p><p> This is just a test 3.</p>
  <div id="ul_1">
  <ul>
<li>這裏是li1</li>
<li>這裏是li2</li>
<li>這裏是li3</li>
<li>這裏是li4</li>
  </ul>
    <ul>
<li>這裏是li1</li>
<li>這裏是li2</li>
<li>這裏是li3</li>
<li>這裏是li4</li>
  </ul>
    <ul>
<li>這裏是li1</li>
<li>這裏是li2</li>
<li>這裏是li3</li>
<li>這裏是li4</li>
  </ul>
  
  </div>
 </body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章