Errors Caused by Space in javascript development

Source: Internet
Author: User

Not to mention nonsense. Let's look at the code first.
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Yiyi garden </title>
</Head>
<Body>
<Div id = "win">
<Ul id = "picChange">
<Li>
</li>
<Li>
</li>
<Li>
</li>
</Ul>
</Div>
<Script type = "text/javascript">
Var pic = document. getElementById ('picchange ');
Var picList = pic. getElementsByTagName ("li ");
Alert (picList [0]. firstChild );
</Script>
</Body>
</Html>

The above code 1 should be run in Firefox and IE respectively. In Firefox, [object Text] appears, while in IE, [object] appears. here, both IE and Firefox use picList [0]. the firstChild object is treated as the object. The Firefox prompt is a Text object, and IE does not prompt more details.
Run the following code to check whether the Code itself is the same, but there is no line feed indentation in li.
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Yiyi garden </title>
</Head>
<Body>
<Div id = "win">
<Ul id = "picChange">
<Li> </li>
<Li> </li>
<Li> </li>
</Ul>
</Div>
<Script type = "text/javascript">
Var pic = document. getElementById ('picchange ');
Var picList = pic. getElementsByTagName ("li ");
Alert (picList [0]. firstChild );
</Script>
</Body>
</Html>

The above Code 2 should be run in Firefox and IE respectively. In Firefox, [object HTMLImageElement] appears, while in IE, [object] appears. here, both IE and Firefox use picList [0]. the firstChild object is treated as an object. Firefox prompts that it is an object of the HTMLImageElement type, and IE does not prompt more details.
The two statements are only the difference between indentation and line feed. The same object is recognized in IE, but different indentation represents different objects in Firefox, firefox's HTML Parsing is confusing.
Let's record it again. I hope you can see it useful. Don't find a solution because of the same problems as me.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.