Home > Web Front-end > JS Tutorial > body text

仅IE6/7/8中innerHTML返回值忽略英文空格的问题_javascript技巧

WBOY
Release: 2016-05-16 18:08:20
Original
1122 people have browsed it

如下

复制代码 代码如下:

jack




div[id=user]中的文本"jack"前有两个英文空格,各浏览器下结果如下

IE6/7/8 : 弹出4,即忽略了空格

IE9/Firefox/Safari/Chrome/Opera : 弹出6,即没有忽略空格

另换成中文空格不会有这个问题。

以下是Gray Zhang的补充:
1、IE6-8下,对于一个元素的firstChild,如果其为TextNode,且nodeValue前n个字符为空格字符(包括空格、 、 、 和一个分页符号U+000C),则这n个字符被忽略
2、在IE6-8下,对一个元素的lastChild,如果其为TextNode,且nodeValue最后n个字符为空格字符(包括空格、 、 、 和一个分页符号U+000C),则这n个字符会被合并为一个空格(ASCII码为32),无论你是\t还是\n,都会变成一个空格
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!