Jquery Mobile下设置radio控件选中

时间:2023-03-09 05:29:30
Jquery Mobile下设置radio控件选中

问题:

.html文件头部引入了:

<script src="js/jquery.js"></script>

<script src="js/jquery.mobile-1.3.2.min.js"></script>

使用jquery.mobile下radio控件:

<input type="radio" name="radio-choice" id="radio-choice-1" value="choice-1" checked="checked" />

<label for="radio-choice-1">Cat</label>

在自定义的.js文件中控制radio控件选中状态时,使用$(“input[type='radio']”).attr("checked","checked");无效。

原因:

需要使用jquery.mobile下新定义的控制选中方法刷新:

$("input[type='radio'] ").attr("checked",true).checkboxradio("refresh");

参考链接:http://jquerymobile.com/demos/1.2.1/docs/forms/radiobuttons/methods.html