HTML--关于innerText, innerHTML, outerText, outerHTML的返回值

来源:互联网 发布:网络用语dt什么意思 编辑:程序博客网 时间:2024/06/02 12:51
Example :
Code html :
   id="pg">Color I like blue

 
innertText : 设置或获取位于对象起始和结束标签内的文本.
Code x :

document.getElementById("pg").innerText

return:

Color I like blue

innerHTML : 设置或获取位于对象起始和结束标签内的HTML 形式的文本(含所有子标签).
Code x :

document.getElementById("pg").innerHTML

return:

Color I like blue

outerText : 该属性返回值和innerText 相同,innerText和outerText在获取时是相同效果;但在设置时,innerText仅设置标签内的文本,而outerText设置包括标签在内的文本。

outerHTML : 设置或获取对象及其内容的 HTML 形式的文本,含标签

Code x :

document.getElementById("pg").outerHTML

return:

Color I like blue

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1771255


原创粉丝点击