where obj.name = "select"; this sentence does not work as expected, whether it is to look at the generated HTML code or to observe the length of the array obtained using Document.getelementsbyname (), you will find that this name setting does not function. Of course this situation only appears in IE6 and IE7, and there is no problem in Firefox.
<textarea id="runcode80349"><ptml> <pead> <title>Test</title> </pead> <body> <div id= "Testdiv "></div> <input type=" button "onclick=" Addinput () "value=" Test0 "> <input type=" button "onclick=" sh ow () "value=" Test1 "> <script type=" text/javascript "> Function addinput () {var div = Document.getelem Entbyid ("Testdiv"); var obj = document.createelement ("input"); Obj.style.width = + "px"; Obj.style.height = + "px"; Obj.name = "Select"; Obj.setattribute ("id", "button1"); document.getElementById ("Testdiv"). AppendChild (Div); Function Show () {Alert (Document.getelementsbyname ("select"). length); } </script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Of course, the solution is simple, when created, using Document.createelement ("<input name= ' select ' >"). But I don't know what the reason is?
There is a word in the description of the Name property:
In Internet Explorer 5, the Name property cannot is set at run time on anchor objects dynamically created with the Createe Lement method. To create a anchor with a NAME attribute, include the attribute and value when using the "CreateElement method", or use the InnerHTML property.