I recently encountered this problem when I was learning JavaScript. First paste the code
1
Operabrowser is used for testing. In the opera console, an error "cannot convert 'document. form1 'to object" is thrown ".
However, if you put Javascript in the body, there is no problem. JS is placed in the body and the head is different. The former is to load and execute JS, while the latter is just to load.
The solution is simple:
1. var txt0000document.form1.txt; put it in the body.
2. var txt0000document.form1.txt; put it in the function.
Another problem exists here. You can add an id = 'test' to the text box and use VaR TXT = Document. getelementbyid ('test'); to replace the original code. In this way, the console will not report errors. Why does document. form1 fail while document. getelementbyid () does?
To be continued .....
I just got back from Beijing after my work.
I searched Google for half a day and did not find the answer. Then I tested it with IE and chrome. VaR TXT = Document. getelementbyid ('test'); is not allowed. So try not to write this global variable in the head. js in the head only loads but does not execute it, and it is different in the body. Load and execute.
The difference between JS head and body http://www.irt.org/script/421.htm