簡體   English   中英

使用JQuery Mobile設置按鈕廣播

[英]Setting button radio with JQuery mobile

庫和JQuery移動用戶界面存在版本問題
我想通過單擊按鈕將值添加到單選按鈕組。

在以下位置進行了測試: http : //jsfiddle.net/BUBtL/4/

提前致謝

<link rel="stylesheet" href="themes/theme-brixky.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile.structure-1.4.0.min.css" />
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>

<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" />
</div>

$(document).ready(function () {

    $("#btn_go").click(function () {

        $('input:radio[name="radio_animal"]').filter('[value="cat"]').attr('checked', true);
    });

    return false;

});

這是一個兼容性問題,您使用的是錯誤的版本組合。

您需要jQuery Mobile 1.4.0及其對應的CSS文件才能與jQuery 1.10.1一起使用

.attr更改為.prop

$('input:radio[name="radio_animal"]').filter('[value="cat"]').prop('checked', true);

檢查jsfiddle

哎呀!

看我的組合:

<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>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM