0

我尝试使用 Jquery Mobile 1.3.2 重现此示例,但它仅适用于 1.2.1 或更低版本。

    $(document).on("pageinit", "#page1", function(){

        $("#checkFirst").click(function(){
            $("input[type='radio']:first").attr("checked", "checked");
            $("input[type='radio']").checkboxradio("refresh");
        });
        $("#checkSecond").click(function(){
            $("input[type='radio']:eq(1)").attr("checked", "checked");
            $("input[type='radio']").checkboxradio("refresh");
        });
        $("#checkLast").click(function(){
            $("input[type='radio']:last").attr("checked", "checked");
            $("input[type='radio']").checkboxradio("refresh");
        });
        $("#uncheckAll").click(function(){
            $("input[type='radio'][checked]").removeAttr("checked");
            $("input[type='radio']").checkboxradio("refresh");
        });
    });

此函数仅在 jqm > 1.2.1 中为一个单选按钮重绘单选按钮第一次

这链接到 jsfiddle:

适用于 1.2.1 的
版本 不适用于 1.3.2 的版本

任何想法为什么这个例子在其他版本中不起作用?

4

2 回答 2

1

使用.prop()而不是.attr()

//to check
$("input[type='radio']:first").prop("checked", true);
//to uncheck
$("input[type='radio']:first").prop("checked", false);

阅读:属性与属性

于 2013-10-01T08:07:38.863 回答
0

使用.prop()而不是.attr()

$("input[type='radio']:first").prop("checked", true);

阅读.prop() 与 .attr()

于 2013-10-01T08:08:39.187 回答