innerText和html之间的区别 [英] Difference between innerText and html
问题描述
innerText
, text()
和 html()之间的区别是什么?
?
推荐答案
innerText
(或< a href =http://docs.jquery.com/Attributes/text =nofollow noreferrer> text()
如果您正在使用jQuery)不包含任何HTML标记。因此,如果你有一个div包含:
innerText
(or text()
if you're using jQuery) doesn't include any HTML tags. So if you had a div that contained:
View my <a href="profile.html">profile</a>
innerText
/ text()
将返回
View my profile
而 html()
将返回
View my <a href="profile.html">profile</a>
由于dcneiner指出 html()
/ text()
是jQuery属性(并且跨浏览器支持),而innerText并非由所有浏览器实现(尽管它适用于最新版本的IE,Safari和Chrome) 。
As dcneiner points out html()
/text()
are jQuery properties (and supported across browsers) while innerText is not implemented by all browsers (although it works in the most recent versions of IE, Safari, and Chrome).
基本上你只想使用 text()
而不是innerText。请参阅 dcneiner的帖子(或 jQuery docs )其他一些使 text()
很棒的东西。
Basically you'll want to use text()
isntead of innerText whenever possible. See dcneiner's post (or the jQuery docs) for some other things that make text()
awesome.
这篇关于innerText和html之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!