【问题标题】:Setting button radio with jQuery mobile and compatibility with JQuery 1.10.1使用 jQuery mobile 设置按钮单选并与 JQuery 1.10.1 兼容
【发布时间】:2014-02-13 01:46:35
【问题描述】:

我尝试通过调用 ajax 设置按钮单选(通过 php 中的请求数据库填写表单)。
我使用 $('input:radio[name="radio_animal"]').filter('[value="cat"]').prop('checked', true);
注意:它适用于 $('#name').val('lastname '); 的所有输入。但按钮收音机没有别的了。

请帮帮我
在线测试: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;
});

【问题讨论】:

标签: jquery jquery-mobile


【解决方案1】:

如果您调用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;

});

【讨论】:

  • oooooooooooooooooooh 效果很好哦谢谢谢谢哦真的谢谢你的帮助。我现在很开心。你让我开心。安德烈
  • @Brolosse 我很高兴它成功了。请将答案标记为已接受,以帮助其他访问者,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-20
  • 2013-05-26
  • 1970-01-01
  • 1970-01-01
  • 2013-07-24
  • 2023-03-17
  • 1970-01-01
相关资源
最近更新 更多