How to get IE7 to change name attribute of radio buttons using plain JavaScript?

社会主义新天地 提交于 2019-12-12 00:00:01

问题


I'm using plain vanilla JavaScript to clone fieldsets and change the ID/name attributes of any of the form fields within the fieldset.

Everything works properly, except in IE7 the cloned radio buttons are all treated as one group. For example, in one fieldset, I have two radio buttons. When I clone it and add another fieldset, then click in the last radio button of the new fieldset, it unchecks the very first radio button.

This appears to be a bug in IE7 where it doesn't change the name attribute (even though everything is working properly in other browsers). I'm using input.getAttribute("name") and have also tried input.htmlName, but neither makes a difference.

Does anyone have any tips on how to get IE7 to treat radio button group for each fieldset as a separate group?

Here's the code I'm using:

input.setAttribute("name", inputName + fieldsetNumber);

Regular text INPUTs work fine, the issue just involves IE7 and radio buttons. From everything I've dug up, there's a bug in IE7 with radio buttons.


回答1:


Ended up using the solution posted here: http://code.rawlinson.us/2006/03/another-ie-gotcha-dynamiclly-created.html to get around this issue.




回答2:


This works, tested.

function changeName(targetId,newName){
 document.getElementById(targetId).name = newName;
}


来源:https://stackoverflow.com/questions/9336173/how-to-get-ie7-to-change-name-attribute-of-radio-buttons-using-plain-javascript

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