One problem with missing VAR:
This is not a standard notation! Do not recommend using
But the effect is still out, why?
Reason:
Https://zhidao.baidu.com/question/1637589020484843580.html
Why the object can be accessed directly by ID, because all element IDs are equivalent to a global variable that holds the object.
There are compatibility issues with direct access to objects through IDs.
It is recommended to get the object in the form of document.getElementById standard.
If an element conforms to either of the two rules below, the Window object must have an attribute corresponding to it, and the property value is the object.
If an element has an id attribute, the property value of the id attribute becomes the property name of the Window object. If an element has the Name property, the property value of the Name property becomes the property name of the Window object. But the tag name for this element must be: A, applet, area, embed, form, frame, frameset, iframe, IMG, Object, one of them.
But if the page has two elements of the same ID, it's a little different:
123<script type= "Text/javascript" >4 functionGetInput () {5 varMydiv = document.getElementById ("Div1");6alert (mydiv.length);//Mydiv is disphtmlelement .7alert (div1.length);//Div1 is disphtmlelementcollection .8 }9</script>Ten One<body> A<div id= "Div1" >123</div> -<div id= "Div1" >456</div> -<input type= "button" value= "Test" onclick= "GetInput ()"/> the</body> -javascript--write Var but can also use tags