JavaScript createelement () Create input cannot set the resolution for the Name property _javascript Tips

Source: Internet
Author: User
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.
Related Article

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.