在IE6中无法选择由jQuery动态生成的单选按钮 [英] Dynamically generated radiobutton by jQuery cannot be selected in IE6

查看:124
本文介绍了在IE6中无法选择由jQuery动态生成的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过jQuery动态生成单选或复选框.
我使用以下代码:

I need to dynamically generate radio or checkbox by jQuery.
I use the following code:

var type = "radio"; // maybe checkbox
$('<input type="'+ type +'">').attr({
            name: "ename", value: "1"
})

但是,无法在IE6中选择生成的广播(其他浏览器也可以). 我该怎么办?

However, the radio generated cannot be selected in IE6(other browsers are fine). What should I do?

marcc的答案解决了我的问题.

marcc's answer solves my problem.

推荐答案

这是IE6的工作方式,不能在动态创建的元素上设置Name属性.

It's the way IE6 works, you cannot set the Name attribute on elements created dynamically.

在attr之前设置Name属性.

Set the Name attribute before the attr.

$('<input type="' + type + '" name="ename">').attr('value', '1');
甚至
$('<input type="' + type + '" name="ename" value="1">');

$('<input type="' + type + '" name="ename">').attr('value', '1');
or even
$('<input type="' + type + '" name="ename" value="1">');

这篇关于在IE6中无法选择由jQuery动态生成的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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