jQuery的层级查找方式分析
本文实例分析了jQuery的层级查找方式。分享给大家供大家参考,具体如下:
下面使用jquery的层级查找方式
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<scriptsrc="jquery-1.6.2.min.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(document).ready(
function(){
/*第一种方式层级查找,查找的是a标签对象——选择器*/
$('.thumb-hovera:has(img)').each(function(){
alert($(this).attr("pid"));
});
/*第三种层级查找,使用方法进行筛选——筛选器*/
$('.thumb-hovera').has("img").each(function(){
alert($(this).attr("pid"));
});
/*第二种方式层级查找,查找的是img标签对象——基本层级选择器*/
$('.thumb-hoveraimg').each(function(){
alert($(this).attr("alt"));
});
}
);
</script>
<title>无标题文档</title>
</head>
<DIVclass=thumbsizcache="17"sizset="84">
<SPANclass=thumb-hoversizcache="17"sizset="84">
<Aclass=lightbox-enabledhref="/user/showuser.php?uid=u1373373094&tab=photo&view=photo_detail&pid=72464692#detail"target=_blankpid="72464692"oid="27"src="http://pic03.babytreeimg-dev.com/foto3/thumbs/2012/0106/43/8/51dc02a6279c0ef6c728e5_mb.jpg"jQuery1640004568396895048288="1">
<IMGalt=DSC_0723.JPGsrc="http://pic05.babytreeimg-dev.com/foto3/thumbs/2012/0106/43/8/51dc02a6279c0ef6c728e5_sm.jpg"></A>
<SPANstyle="DISPLAY:none"id=72464692class=mouse-wrap>
<IMGclass=unselectsrc="http://pic.babytree.com/img/mybabytree/photo/pix.png">
</SPAN>
</SPAN>
</DIV>
<DIVclass=thumb>
<SPANclass=thumb-hoversizcache="0"sizset="2">
<Aclass=lightbox-enabledhref="/user/showuser.php?uid=u3073373044&tab=photo&view=photo_detail&pid=72464732#detail"target=_blankpid="72464732"oid="5"src="http://pic02.babytreeimg-dev.com/foto3/thumbs/2012/0216/48/9/b72ff3742c8c172650a0d1_nb.jpg"jQuery16405726906849340585="1"><IMGalt=Koala.jpgsrc="http://pic01.babytreeimg-dev.com/foto3/thumbs/2012/0216/48/9/b72ff3742c8c172650a0d1_sm.jpg"></A>
<SPANstyle="DISPLAY:none"id=72464732class=mouse-wrap>
<IMGclass=unselectalt=DSC_0724.JPGsrc="http://pic.babytree.com/img/mybabytree/photo/pix.png">
</SPAN>
</SPAN>
</DIV>
<body>
</body>
</html>
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery常用插件及用法总结》、《jquery中Ajax用法总结》、《jQuery表格(table)操作技巧汇总》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。