在一个项目里需要用JavaScript动态建立radio buttons,然后替换span element下的内容,在IE里能显示出来,可就是无法做选择,郁闷了半天,后来查网上资料发现是IE的BUG,说是
"IE doesn’t allow the name attribute to be changed after the element is created“,可我试了下Checkbox就不存在此问题。
原代码:
function createCxtjRadioButtons(data,cxtjId,cxtjTagId){
var tagCxtj = document.getElementById(cxtjTagId);
tagCxtj.removeChild(tagCxtj.childNodes[0]);
for (var key in data) {
var val = data[key];
var input = document.createElement("input");
input.setAttribute("name",cxtjId);
input.setAttribute("type","radio");
input.setAttribute("value",key);
tagCxtj.appendChild(input);
var label = document.createElement("label");
label.setAttribute("for",input_id);
label.appendChild(document.createTextNode(val));
tagCxtj.appendChild(label);
}
}
解决后:
function createCxtjRadioButtons(data,cxtjId,cxtjTagId){
var tagCxtj = document.getElementById(cxtjTagId);
tagCxtj.removeChild(tagCxtj.childNodes[0]);
for (var key in data) {
var val = data[key];
var input = createElement("input", cxtjId);
input.setAttribute("type","radio");
input.setAttribute("value",key);
tagCxtj.appendChild(input);
var label = document.createElement("label");
label.setAttribute("for",input_id);
label.appendChild(document.createTextNode(val));
tagCxtj.appendChild(label);
}
}
function createElement(type, name) {
var element = null;
try {
// First try the IE way; if this fails then use the standard way
element = document.createElement('<'+type+' name="'+name+'">');
} catch (e) {
// Probably failed because we’re not running on IE
}
if (!element) {
element = document.createElement(type);
element.name = name;
}
return element;
}
参考:
1、http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/
2、http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/
分享到:
相关推荐
Segmented Radio Buttons介绍: 在Android中实现类似iOS的分段单选按钮(segmented control)。 测试环境: Eclipse 4.2, Android 3.0 以上。 注意:测试环境并不代表适用环境。
SelectorViewDrawable用于在运行时为诸如Buttons,TextViews,RadioButtons等的视图创建选择器,而不是在drawable文件夹中添加多个xml资源。 有关教程,请访问我的博客
This demonstrates how to add radio buttons to your menus
《WPF Tips: Uncheckable radio buttons》一文的可执行程序示例与源代码。 原文网址:http://blog.csdn.net/xinyaping/article/details/7887663 作者:辛亚平 工程文件为Visual Studio 2008 with .Net Framework 3.5...
如何往IE工具条添加按钮 Adding Toolbar Buttons往IE上添加工具条 用VC在IE浏览器的工具条上添加命令按钮.zip
入门偷看(可以做很多事情)安装npm i react-native-radio-buttons-group --save或者yarn add react-native-radio-buttons-group用法 Javascript范例 App.js import React, { useState } from 'react';import ...
VC++设置和获得一组单选按钮的选中状态
当利用text或textarea元素输入字符值改变时发该事件,同时当在select表格项中一个选项状态改变后也会引发该事件。例: <Form> ('this.test)"> </Form> 7.onSubmit事件:属于表单元素,写在表单标签内。语法:...
npm install radio-buttons-react-native --save 用法 import RadioButtonRN from 'radio-buttons-react-native'; const data = [ { label: 'data 1' }, { label: 'data 2' } ]; selectedBtn={(e)> console....
Buttons提供一套给用户添加自定义按钮的特性,让按钮看起来和表格是一个整体。 Buttons提供了一些基本的按钮,比如打印,导出之类的按钮,也提供了API让用户自己扩展按钮,触发自定义的操作。 当在DataTable中显示...
纯样式实现Radio单选框的分享代码
安卓开发通过ViewPage和RadioButton+SharedPreferences实现欢迎页
纽扣DataTables的Buttons扩展提供了一组通用的选项,API方法和样式,以在将与DataTable交互的页面上显示按钮。 还提供了用于数据导出,打印和列可见性控制的模块。安装使用Buttons获得软件的主要方法是使用。 您还...
android-03-radiobuttons
react-custom-radio-buttons-group 是一个精心设计的单一React组件,可帮助您创建单选按钮组。 安装/入门 这个包在 NPM 存储库中作为 react-custom-radio-buttons-group 提供。 它将与所有流行的打包器一起正常工作...
Rasa自定义选择按钮buttons——选择性别 https://xercis.blog.csdn.net/article/details/106618930
Navigation Buttons
这不,一个名叫Actual Title Buttons的小工具就是专门用来对标题栏中的图标进行更改的,没想到吧。通过使用这一工具,你可以为普通窗口标题栏增加“最小化至系统托盘”和“总在最上面”两个特殊的按钮。
有关此问题的进一步讨论可以在找到 兼容性 Ember.js v3.4或更高版本 Ember CLI v2.13或更高版本 Node.js v8或更高版本 安装 ember install ember-radio-buttons 用法 在此插件的早期版本中,您需要在应用程序中...
RadioButtons继承自UIControl,因此您可以轻松地对其进行管理。 支持2种样式: standard -类似于UITableView纯样式和grouped -类似于UITableView insertGrouped样式 垂直和水平放置。 按颜色类型的属性,缩进也可以...