如何使IE7使用纯JavaScript更改单选按钮的名称属性? [英] How to get IE7 to change name attribute of radio buttons using plain JavaScript?

查看:69
本文介绍了如何使IE7使用纯JavaScript更改单选按钮的名称属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用普通的JavaScript JavaScript来克隆字段集并更改字段集内任何表单字段的ID /名称属性。

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

除在IE7中,克隆的单选按钮都被视为一组。例如,在一个字段集中,我有两个单选按钮。当我克隆它并添加另一个字段集,然后单击新字段集的最后一个单选按钮时,它将取消选中第一个单选按钮。

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.

这似乎是一个错误在IE7中,它不会更改name属性(即使在其他浏览器中一切正常)。我使用的是input.getAttribute( name),也尝试过使用input.htmlName,但是两者都没有区别。

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.

有人对如何获取有任何提示吗? IE7会将每个字段集的单选按钮组视为一个单独的组?

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

这是我使用的代码:

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

常规文本输入工作正常,问题仅涉及IE7和单选按钮。从我挖出的所有内容来看,IE7中有一个带有单选按钮的bug。

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.

推荐答案

最终使用了此处发布的解决方案: http://code.rawlinson.us/2006/03 /another-ie-gotcha-dynamiclly-created.html 解决此问题。

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

这篇关于如何使IE7使用纯JavaScript更改单选按钮的名称属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆