jquery – radio Buttons和.attr(‘checked’,’checked’)在IE7中不起作用

有没有办法在IE7中附加检查单选按钮?

似乎在每个浏览器中都可以工作,看起来好像在IE6,7中有所作为,尽管我正在阅读无处不在.我完全不知道为什么它不工作.

var $itemVariantRowRadio = $("<input/>")
    .attr("type","radio")
    .attr("name","itemvariant")
    .addClass("itemvariant")
    .val('whatever');


    $itemVariantRowRadio.attr('checked','checked');
    $itemVariantRow.append($itemVariantRowRadio)

现在,如果我在IE6 / 7中做了一个console.log($itemVariantRowRadio.attr(‘checked’)),那么它表示它被设置为TRUE,但收音机实际上并没有被检查或者被选中.

恶梦!其他任何人都会遇到这种情况吗?

解决方法

如果在jQuery> = 1.6:

使用道具,如下所示:.prop() vs .attr()

$itemVariantRowRadio.prop('checked',true);

如果在jQuery< 1.6:

$itemVariantRowRadio.attr('checked',true);

也:

尝试像这样创建你的元素:

var $itemVariantRowRadio = $("<input/>",{
     type: 'radio',name: 'itemvariant',class: 'itemvariant',checked: true,value: 'whatever'
});
$itemVariantRow.append($itemVariantRowRadio);

见小提琴:http://jsfiddle.net/maniator/6CDf3/
附有2个输入的示例:http://jsfiddle.net/maniator/6CDf3/2/

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...