innerText和outerText有什么区别? [英] What is the difference between innerText and outerText?

查看:88
本文介绍了innerText和outerText有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过网络搜索后,我了解innerHTML和outerHTML之间的区别。

After searching through web i understood the difference between innerHTML and outerHTML.

然而,我很难理解innerText和outerText之间的区别。
对我来说,这两个出现几乎相同。

However i am having hard time understanding the difference between innerText and outerText. Both appear almost same to me.

任何人都可以帮助我理解这一点吗?

Can anyone help me understand this with a nice illustration ?

谢谢!

推荐答案

innerText 仅更改HTML标签内的文字,例如

innerText changes only text within HTML tags, e.g.

<div>
  <p>Change Me</p>
</div>

p.innerText = "Changed!"

成为

<div>
  <p>Changed!</p>
</div>

而$ code> outerText :

Whereas outerText:

<div>
  <p>Change Me</p>
</div>

p.outerText = "Changed!"

成为

<div>
   Changed!
</div>

这篇关于innerText和outerText有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆