欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery獲取節(jié)點(diǎn)和子節(jié)點(diǎn)文本的方法

 更新時(shí)間:2014年07月22日 17:27:35   投稿:whsnow  
本節(jié)主要介紹了jQuery如何獲取節(jié)點(diǎn)和子節(jié)點(diǎn)文本,下面有個(gè)示例,大家可以參考下

對(duì)于下面的html片段,

<div id="text_test">test text<a href="techbrood.com" rel="external nofollow" >techbrood co.</a></div>

獲取節(jié)點(diǎn)純文本:

var text = $('#text_test').text()

這個(gè)會(huì)得到“test text techbrood co.”,也就是會(huì)把當(dāng)前元素的所有節(jié)點(diǎn)(包含子節(jié)點(diǎn))的文本讀取出來(lái)。

如果只想獲取主節(jié)點(diǎn)的文本,方法復(fù)雜點(diǎn):

var text = $("#text_test").contents().filter(function() {
return this.nodeType === 3;
}).text();

獲取某子節(jié)點(diǎn)的文本:

var text = $("#text_test > a").first().contents().filter(function() {
return this.nodeType === 3;
}).text();

相關(guān)文章

最新評(píng)論