我尝试通过调用ajax来设置按钮无线电(php中的请求数据库填写表单)。
我使用$('输入:无线电[name =" radio_animal"]')。滤波器('[value =" cat"]')。prop('checked',true);
注意:它对所有输入都有效。但是没有其他按钮收音机。
请帮助我
在线进行测试:http://jsfiddle.net/brolosse/bubtl/
检查我的代码:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>
<input id="input_text" type="text">
<fieldset data-role="controlgroup" id="field_radio_amis">
<legend></legend>
<label for="cat">Cat</label>
<input type="radio" name="radio_animal" id="cat" class="custom" value="cat" />
<label for="dog">Dog</label>
<input type="radio" name="radio_animal" id="dog" class="custom" value="dog" />
</fieldset>
<input type="button" name="btn_go" id="btn_go" value="Click to set button radio and inputbox" />
$(document).ready(function () {
$("#btn_go").click(function () {
$('#input_text').val('It's OK ! but no radio check')
$('input:radio[name="radio_animal"]').filter('[value="cat"]').prop('checked', true);
});
return false;
});
如果您致电checkboxradio("refresh");
,它将正确渲染。
http://jsfiddle.net/ydt5f/
$(document).ready(function () {
$("#btn_go").click(function () {
$('#input_text').val('It's OK ! The radio looks good :)')
$('input:radio[name="radio_animal"]').filter('[value="cat"]').prop('checked', true).checkboxradio("refresh");
});
return false;
});