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

Only the innerHTML return value in IE6/7/8 ignores the problem of English spaces_javascript skills

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

As follows

Copy the code The code is as follows:

jack< ;/div>
<script> <br>alert(document.getElementById('user').innerHTML.length); <br></script>


There are two English spaces before the text "jack" in div[id=user]. The results in each browser are as follows

IE6/7/8: 4 pops up, that is, the spaces are ignored

IE9/Firefox/Safari/Chrome/Opera: 6 pops up, that is, the spaces

are not ignored. Changing to Chinese spaces will not cause this problem.

The following is Gray Zhang’s addition:
1. Under IE6-8, for the firstChild of an element, if it is TextNode, and the first n characters of nodeValue are space characters (including spaces, , , and a page break symbol U 000C), then these n characters are ignored
2. Under IE6-8, for the lastChild of an element, if it is TextNode, and the last n characters of nodeValue are space characters (including spaces, , , and a page break symbol U 000C), then these n characters will be combined into a space (ASCII code is 32), whether you are t or n, it will become a space
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!