javascript createElement()创建input不能设置name属性的解决方法
更新时间:2009年10月11日 14:05:27 作者:
今天在使用document.createElement()动态创建input时,发现不能为其name赋值,以下是测试代码。
其中obj.name = "select";这句话并不能起到预期的作用,无论是看生成后的HTML代码还是观察使用document.getElementsByName()获取的数组长度,都会发现这个name设置并没有起作用。当然这种情况只出现在IE6和IE7中,而在FireFox中是没有问题的。
[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
当然解决方法很简单,在创建时,使用document.createElement("<input name='select'>")。不过还不知道是什么原因?
在Name属性的说明中有这样一句话:
In Internet Explorer 5, the name property cannot be set at run time on anchor objects dynamically created with the createElement method. To create an anchor with a NAME attribute, include the attribute and value when using the createElement method, or use the innerHTML property.
[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
当然解决方法很简单,在创建时,使用document.createElement("<input name='select'>")。不过还不知道是什么原因?
在Name属性的说明中有这样一句话:
In Internet Explorer 5, the name property cannot be set at run time on anchor objects dynamically created with the createElement method. To create an anchor with a NAME attribute, include the attribute and value when using the createElement method, or use the innerHTML property.
您可能感兴趣的文章:
- 浅谈javascript中createElement事件
- Javascript createElement和innerHTML增加页面元素的性能对比
- 动态添加option及createElement使用示例
- 动态的创建一个元素createElement及删除一个元素
- js 用CreateElement动态创建标签示例
- 使用jQuery解决IE与FireFox下createElement方法的差异
- document.createElement()用法
- createElement和onclick
- 动态加载js文件 document.createElement
- javascript中createElement的两种创建方式
相关文章
silverlight线程与基于事件驱动javascript引擎(实现轨迹回放功能)
前一段时间一直在重构工作站轨迹回放功能,一开始我觉得很简单,但是后面引发了一系列奇怪的问题,让我很蛋疼,所以不得不写个总结加深记忆。2011-08-08设为首页加入收藏兼容360/火狐/谷歌/IE等主流浏览器的代码
不用找了我试过好多次ie、火狐、谷歌浏览器此代码都是不可逆兼容,想把这个问题完全解决,方法就是像其他主流网站一样,下面是我的简单解决方案2013-03-03IE6/7中getAttribute获取href/src 属性(相对路径0值与其它浏览器不同
IE6/7中getAttribute获取href/src 属性(相对路径0值与其它浏览器不同的解决方法2011-08-08
最新评论