在IE6中无法选择由jQuery动态生成的单选按钮 [英] Dynamically generated radiobutton by jQuery cannot be selected in IE6
问题描述
我需要通过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屋!