子元素过滤选择器:
l nth-child() 选择器详解如下:
• (1) :nth-child(even/odd): 能选取每个父元素下的索引值为偶(奇)数的元素
• (2):nth-child(2): 能选取每个父元素下的索引值为2 的元素
• (3):nth-child(3n): 能选取每个父元素下的索引值是3 的倍数的元素
• (3):nth-child(3n + 1): 能选取每个父元素下的索引值是 3n + 1的元素
<ul>
<li>
Jone
</li>
<li>
Karl
</li>
<li>
Brandon
</li>
</ul>
<ul>
<li>
Glen
</li>
<li>
Tane
</li>
<li>
Ralph
</li>
</ul>
$("ul>li:nth-child(even").css("background-color","red");
$("ul>li:first-child").css("background-color","blue");
$("ul>li:last-child").css("background-color","red");
$("ul>li:only-child").css("background-color","green");
表单对象过滤器:
此选择器主要对所选择的表单元素进行过滤
<divalign="center">
<form>
<inputtype="button" value="Input Button" /><br/>
<inputtype="checkbox" /><br/>
<inputtype="file" /><br/>
<inputtype="hidden" /><br/>
<inputtype="image" src="./images/IMAG0186.jpg"width="50px" height="50px"/><br/>
<inputtype="password" /><br/>
<inputtype="radio" /><br/>
<inputtype="reset" /><br/>
<inputtype="submit" /><br/>
<inputtype="text" /><br/>
<select>
<option>
Option
</option>
</select><br/>
<textarea></textarea><br/>
<button>
Button
</button>
</form>
<divid="ts">
<inputtype="password" /><br/>
</div>
</div>
$(document).ready(function(){
// 表单 过滤器匹配所有 input, textarea, select 和 button 元素
var $ipts = $(":input");
//alert($ipts.length);
//alert($(":text").length);
alert($("input:text").length);// input : text
});
前提:引入js文件