首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查来自pageinit的单选按钮不起作用

检查来自pageinit的单选按钮不起作用
EN

Stack Overflow用户
提问于 2012-08-11 11:45:49
回答 3查看 1.2K关注 0票数 1

以下代码不起作用,单选按钮未选中。知道为什么吗?

我也尝试过attr('checked', 'checked')

代码语言:javascript
复制
<html>
<head>      
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>      
    <script type="text/javascript">
    $(document).bind("pageinit", function () {           
        $('#radio-pet-2a').attr('checked', true);
    });         
    </script>
  </head>
 <body>

<div data-role="content">

    <ul data-role = "listview">

        <li>
        <fieldset data-role="controlgroup">
        <legend>Choose a pet:</legend>
             <input type="radio" name="radio-pet" id="radio-pet-1a" value="choice-1"   />
             <label for="radio-pet-1a">Cat</label>

             <input type="radio" name="radio-pet" id="radio-pet-2a" value="choice-2"  />
             <label for="radio-pet-2a">Dog</label>

             <input type="radio" name="radio-pet" id="radio-pet-3a" value="choice-3"  />
             <label for="radio-pet-3a">Hamster</label>

             <input type="radio" name="radio-pet" id="radio-pet-4a" value="choice-4"  />
             <label for="radio-pet-4a">Lizard</label>
    </fieldset>
        </li>

    </ul>
</div>

</body>
</html>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-08-12 00:08:59

我已经想出了让它工作的方法:

代码语言:javascript
复制
    $(document).bind("pageinit", function () {           
        $('#radio-pet-2a').attr('checked', true);
        $("input[type='radio']").checkboxradio("refresh"); 
    });     
票数 0
EN

Stack Overflow用户

发布于 2012-11-07 23:22:16

尝试使用prop方法设置单选按钮的属性检查,然后刷新单选按钮。

代码语言:javascript
复制
$(document).bind("pageinit", function () {           
    $('#radio-pet-2a').prop("checked", true).checkboxradio("refresh");
});
票数 2
EN

Stack Overflow用户

发布于 2012-08-11 12:11:44

更改逻辑设置后,需要使用button('refresh')更新渲染:

代码语言:javascript
复制
$(document).bind("pageinit", function () {           
    $('#radio-pet-2a').attr('checked', true).button('refresh');
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11911728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档