juicy-initial

jQuery.text()方法时候,会把子元素的文本也获取到,以下方法可获取自身文本节点,不包括子元素

<div id="demo">只获取我<a href="">别管我</a></div>

var a = $ ("#demo").prop (\'firstChild\').nodeValue;
console.log(a);
<div id="demo">只获取我<a href="">别管我</a></div>

var a = document.getElementById(\'demo\').firstChild.nodeValue;
console.log(a);

 

分类:

技术点:

相关文章:

  • 2021-10-16
  • 2021-11-29
  • 2021-08-12
  • 2021-12-10
  • 2021-10-16
  • 2022-12-23
猜你喜欢
  • 2021-11-12
  • 2021-11-14
  • 2022-01-17
  • 2021-05-29
  • 2022-12-23
  • 2021-12-10
相关资源
相似解决方案