jquery 如何獲取標籤自己的文本內容,不包含子元素

 <li><a href="http://gz.ihk.cn/esf/houselist/?lp=保利花園" ><strong id="aaaa">保利花園<b>海珠 工業大道中</b></strong></a></li>html

本人想要獲取保利花園node

實現方法:code


一:htm

var obj = $("#aaaa").clone();
obj.find(':nth-child(n)').remove();
console.log(obj.html());

 

二:rem

var str = $('#aaaa').contents().filter(function (index, content) {

    return content.nodeType === 3;

}).text();
相關文章
相關標籤/搜索