test.innerhtml:
也就是从对象的起始位置到终止位置的全部内容,包括html标签。
上例中的test.innerhtml的值也就是“test1 test2 ”。
test.innertext:
从起始位置到终止位置的内容, 但它去除html标签
上例中的text.innertest的值也就是“test1 test2”, 其中span标签去除了。
test.outerhtml:
除了包含innerhtml的全部内容外, 还包含对象标签本身。
上例中的text.outerhtml的值也就是test1 test2
完整示例:
复制代码 代码如下:
test1 test2
innerhtml内容
inerhtml内容
outerhtml内容
特别说明:
innerhtml是符合w3c标准的属性,而innertext只适用于ie浏览器,因此,尽可能地去使用innerhtml,而少用innertext,如果要输出不含html标签的内容,可以使用innerhtml取得包含html标签的内容后,再用正则表达式去除html标签,下面是一个简单的符合w3c标准的示例:
无html,符合w3c标准
复制代码 代码如下:
nothing