Javascript appendChild name property

血红的双手。 提交于 2019-12-11 17:12:16

问题


So I'm trying to add attributes to a radio button input, specifically the name attribute in Javascript. I'm appending children to a main object and when I use Object.setAttribute("name", value); and subsequently check the innerHTML of the appended input, it does not even contain a name property at all!

I'm guessing I'm missing something simple or there is a way around it but I've been wrestling with this problem for quite a while with no success. I tried accessing the property directly using Object.name = value and Object.nodeName = value (that one was a random try).

Is there some sort of problem in which IE6's javascript rendering engine does not recognize setAttribute("name", value)? Is there a way around it?


回答1:


Here's a workaround for dealing with IE:

http://javascript.about.com/library/bliebug2.htm

http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/

Essentially, the method used is to create the elements on the fly instead of modifying existing elements.




回答2:


In IE, you cannot add a name attribute on dynamically created objects.

I suggest using id if unique, or a class if not.



来源:https://stackoverflow.com/questions/1711100/javascript-appendchild-name-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!