-1
例HTML而不是文本:檢查元素包含子標籤使用JavaScript
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero.</p>
<p><img src="..." alt=""/></p>
<p><iframe width="" height="" src="...">....</iframe></p>
<p> Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urn</p>
我怎樣纔能有效地得到這些p標籤包含了使用純JavaScript代碼,而不是文本,如果可能的話?
的結果應該是:
<p><img src="..." alt=""/></p>
<p><iframe width="" height="" src="...">....</iframe></p>
我已經走近它,像這樣:
var ptags = document.querySelectorAll(".container p");
for(var i = 0; i<ptags.length; i++) {
if(ptags[i].querySelectorAll("img, iframe").length > 0) { .... }
}
感謝利昂,childElementCount財產是我一直在尋找。 – g13