Javascript troubleshooting notes

Source: Internet
Author: User

It's time to hide your laziness.
Today, a colleague asked me a strange question: A piece of javascript can be executed normally after it is put out of the function, but it is always wrong when it is triggered by a button in a function!
I looked at hisCode(The following code is a copy of the original code. The original code is not a Textbox, but an invisible ActiveX Object ):

< Input type = " Text " ID = " Txt01 " Value = " 0001 " >
< Input type = " Text " ID = " Txt02 " Value = " 0002 " >
< Input type = " Button " Value = " Test " Onclick = " Test () " >
< Script Language = " Javascript " >
// Function Test ()
// {
Alert(document.all.txt 01. value );
Document.write(document.all.txt 01. value );
Alert(document.all.txt 02. value );
Document.write(document.all.txt 02. value );
// }
</ Script >

limit 02. value is null or not an object.
at the beginning, I was puzzled. I even thought that the ActiveX object had expired because of its security. But I thought, if so, why is function normal? I checked the code again and again, but I couldn't find the problem. It wasn't until I suddenly saw "document. Write" that I remembered. After blocking all document. Write, everything was normal.
everything was originally a document. write is a zombie. If the current page has been loaded, its execution will clear all the webpage components loaded for the first time. If the current page is being loaded, then its execution will only add content after the current load code. This is the cause of the above problem.

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.