吉福美食网
您的当前位置:首页JQuery学习笔记选择器之五_jquery

JQuery学习笔记选择器之五_jquery

来源:吉福美食网


代码如下:





$(function(){
$("#aFirst").click(function(){
$("div[id]").each(function(){
$(this).css("background","#773300");
})
})
$("#aSecond").click(function(){
$("div[id = div2]").each(function(){
$(this).css("background","#8833ff");
})
})
$("#aThird").click(function(){
$("div[id != div2]").each(function(){
$(this).css("background","#87f2");
})
})
$("#aFourthly").click(function(){
$("div[name ^= DIV]").each(function(){
$(this).css("background","#140586");
})
})
$("#aFifthly").click(function(){
$("div[name $= ly]").each(function(){
$(this).css("background","#930584");
})
})
$("#aSixth").click(function(){
$("div[name *= th]").each(function(){
$(this).css("background","#099483");
})
})
$("#aSeventh").click(function(){
$("div[id][name !=Fifthly][name *= i]").each(function(){
$(this).css("background","#938607");
})
})
})
// -->
无标题文档


重置
div1
div2
div3
div4
div5

设置页面所有DIV元素的背景颜色|
设置第2个DIV的背景颜色|
设置除第2个DIV以外DIV的背景颜色|
设置name属性值以DIV开头的元素|
设置name属性值以ly结尾的元素|
设置name属性值包含th的元素|
综合应用




1.$("selector [Attribute]")--注,以下直接简写为[Attribute]
描述:获取selector选择的元素集合里,拥有Attribute属性的元素集合。应该较为简单,在这就不做啥详细说明了,有不了解的跟下贴,哈
返回值:Array(Element);
2.[attribute=value]
描述:获取selector选择的元素集合里,拥有Attribute属性值等于Value的元素集合。
返回值:Array(Element);
3.[attribute!=value]
描述:获取selector选择的元素集合里,拥有Attribute属性值不等于Value的元素集合。
返回值:Array(Element);
4.[attribute^=value]
描述:获取selector选择的元素集合里,拥有Attribute属性值以Value开头的元素集合。相当于正则的规范^^
返回值:Array(Element);
5.[attribute$=value]
描述:获取selector选择的元素集合里,拥有Attribute属性值以Value结尾的元素集合。相当于正则的规范^^
返回值:Array(Element);
6.[attribute*=value]
描述:获取selector选择的元素集合里,拥有Attribute属性值包含Value的元素集合。
返回值:Array(Element);
7.[selector1][selector2][selectorN]
描述:与第一章中,基本选择器综合应用一样,此方法也就是前6种的综合版,就如我例子中$("div[id][name !=Fifthly][name *= i]")就是取所有的div元素中,拥有ID属性&&name属性!=Fifthly&&name属性包含字符i的DIV元素的集合,大家用我例子试下就能很清楚的了解看到效果了,哈。好好利用此方法应该很有用^^
返回值:Array(Element);

显示全文