code1992

jQuery 获取 div 之间的内容,有两种方法,$(selector).text()、$(selector).html() 。

 

html:

<div>
<p>test</p>
</div>

 

$("div").text() 得到的是 test,是 div 的纯文本,会自动忽略 html 标签 。 

$("div").html() 得到的是 <p>test</p>,是 div 的所有内容,包括 html 标签,它有个好处是可以将 得到的标签与文字 直接再利用,比如添加到页面其他地方之类的操作 。

分类:

技术点:

相关文章:

  • 2021-09-25
  • 2022-12-23
  • 2021-11-29
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-12-25
猜你喜欢
  • 2022-01-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案