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.