以下代码不起作用,单选按钮未选中。知道为什么吗?
我也尝试过attr('checked', 'checked')。
<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>发布于 2012-08-12 00:08:59
我已经想出了让它工作的方法:
$(document).bind("pageinit", function () {
$('#radio-pet-2a').attr('checked', true);
$("input[type='radio']").checkboxradio("refresh");
}); 发布于 2012-11-07 23:22:16
尝试使用prop方法设置单选按钮的属性检查,然后刷新单选按钮。
$(document).bind("pageinit", function () {
$('#radio-pet-2a').prop("checked", true).checkboxradio("refresh");
});发布于 2012-08-11 12:11:44
更改逻辑设置后,需要使用button('refresh')更新渲染:
$(document).bind("pageinit", function () {
$('#radio-pet-2a').attr('checked', true).button('refresh');
});https://stackoverflow.com/questions/11911728
复制相似问题