js---使用JS向页面动态添加radio

[code]
开发过程中,需要使用JS向页面动态添加radio,实现时通过document.createElement()方法来实现,刚开始的代码如下:
1. var _radio = document.createElement("input");
2. _radio.type = "radio";
3. _radio.name = "_radio";
4. document.body.appendChild(_radio);
5. _radio = document.createElement("input");
6. _radio.type = "radio";
7. _radio.name = "_radio";
8. document.body.appendChild(_radio);
结果在IE浏览器上生成的raido无法选中,而使用firefox浏览器却可以选中。后来试了下面的代码:
1. var _radio = document.createElement("<input type='radio' name='_radio'>");
2. document.body.appendChild(_radio);
3. _radio = document.createElement("<input type='radio' name='_radio'>");
4. document.body.appendChild(_radio);
结果在IE上生成的radio可以选中了,但firefox浏览器中却无效。为此,对于不同的浏览器&#x
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
echarts 是一款非常流行的数据可视化工具,可以用来快速绘制各种图表。在 echarts 中添加 el-radio-button 可以用来实现图表中的单选按钮,具体操作步骤如下: 1. 安装 echarts 和 element-ui 在项目中安装 echarts 和 element-ui,可以通过以下命令进行安装: ``` npm install echarts --save npm install element-ui --save ``` 2. 引入 echarts 和 element-ui 在需要使用 echarts 的页面中引入 echarts 和 element-ui: ```javascript import echarts from 'echarts' import { RadioGroup, RadioButton } from 'element-ui' Vue.use(RadioGroup) Vue.use(RadioButton) ``` 3. 在图表中添加 el-radio-button 在图表的 option 中添加一个包含 el-radio-button 的组件: ```javascript { title: { text: '柱状图示例' }, tooltip: {}, legend: { data:['销量'] }, xAxis: { data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"] }, yAxis: {}, series: [{ name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }], toolbox: { feature: { dataView: {show: true, readOnly: false}, magicType: {show: true, type: ['line', 'bar']}, restore: {show: true}, saveAsImage: {show: true} } }, // 添加 el-radio-button 组件 graphic: { type: 'group', left: 'center', top: 'bottom', children: [ { type: 'radioButtonGroup', id: 'bar-radio-group', left: 0, top: 0, children: [ { type: 'radioButton', id: 'bar-radio-1', value: 'bar', text: '柱状图', textStyle: { fontSize: 12 }, width: 70, height: 20, borderColor: '#000', backgroundColor: '#fff' }, { type: 'radioButton', id: 'bar-radio-2', value: 'line', text: '折线图', textStyle: { fontSize: 12 }, width: 70, height: 20, borderColor: '#000', backgroundColor: '#fff' } ], onChange(idx) { if (idx === 0) { chart.setOption({ series: [{ name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }) } else if (idx === 1) { chart.setOption({ series: [{ name: '销量', type: 'line', data: [5, 20, 36, 10, 10, 20] }] }) } } } ] } } ``` 4. 相关问题: 1. 如何在 echarts 中添加其他 element-ui 组件? 2. 如何使用 echarts 绘制折线图? 3. 如何使用 echarts 绘制饼图?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值