jquery find 推荐
https://codeplayer.vip/p/j7soa
这篇写的还是不错的,备用。
// 返回jQuery对象所有匹配元素的标识信息数组
// 每个元素形如:tagName或tagName#id(如果有id的话)
function getTagsInfo($doms){
return $doms.map(function(){
return this.tagName + (this.id ? "#" + this.id : "");
}).get();
}
// 匹配id为e1的元素
var $e1 = $("#e1");
var $e1_span = $e1.find("span");
document.writeln( getTagsInfo( $e1_span ) ); // SPAN#e2,SPAN#e3,SPAN#e4,SPAN#e5
var $p = $("p");
var $p_span = $p.find("span");
document.writeln( getTagsInfo( $p_span ) ); // SPAN#e2,SPAN#e3,SPAN#e4,SPAN#e5,SPAN#e7
var $highlight = $p.find( $(".highlight") );
document.writeln( getTagsInfo( $highlight ) ); // SPAN#e7
var a = document.getElementsByTagName("a");
var $a = $p.find( a );
document.writeln( getTagsInfo( $a ) ); // A#e8