zl程序教程

您现在的位置是:首页 >  其他

当前栏目

javascriptcreateElement()创建input不能设置name属性的解决方法

属性方法 解决 设置 创建 不能 name input
2023-06-13 09:14:13 时间
其中obj.name="select";这句话并不能起到预期的作用,无论是看生成后的HTML代码还是观察使用document.getElementsByName()获取的数组长度,都会发现这个name设置并没有起作用。当然这种情况只出现在IE6和IE7中,而在FireFox中是没有问题的。
    Test       
          

  当然解决方法很简单,在创建时,使用document.createElement("<inputname="select">")。不过还不知道是什么原因?
  在Name属性的说明中有这样一句话:
InInternetExplorer5,thenamepropertycannotbesetatruntimeonanchorobjectsdynamicallycreatedwiththecreateElementmethod.TocreateananchorwithaNAMEattribute,includetheattributeandvaluewhenusingthecreateElementmethod,orusetheinnerHTMLproperty.