contents
英 ['k?ntents]? ?美 ['k?ntents]??
n.內(nèi)容;含量;(書、講話、節(jié)目等的)主題;所含之物( content的名詞復數(shù) );(書等的)內(nèi)容,目錄;容量,含量;(書、講話、節(jié)目等的)主題
jquery contents()方法 語法
作用:contents() 方法獲得匹配元素集合中每個元素的子節(jié)點,包括文本和注釋節(jié)點。
語法:.contents()
說明:如果給定表示 DOM 元素集合的 jQuery 對象,.contents() 方法允許我們檢索 DOM 樹中的這些元素的直接子節(jié)點,并用匹配元素構(gòu)造新的 jQuery 對象。.contents() 和?.children()?方法類似,不同的是前者在結(jié)果 jQuery 對象中包含了文本節(jié)點以及 HTML 元素。.contents() 方法也可以用于獲得 iframe 的內(nèi)容文檔,前提是該 iframe 與主頁面在同一個域。
jquery contents()方法 示例
<!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <p>Hello <a href="http://php.cn/">Apple</a>, how are you doing?</p> <script>$("p").contents().filter(function(){ return this.nodeType != 1; }).wrap("<b/>");</script> </body> </html>
點擊 "運行實例" 按鈕查看在線實例