如何通过代码检查jquery移动单选按钮集

Beh*_*zan 2 jquery-mobile

我使用jquery mobile来构建一个Phonegap应用程序.我创建像这样的任何收音机:

在此输入图像描述

我想检查开关盒中的收音机!

switch (font_family){ case 'tahoma': $('#radio-1').checked(); ... }
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗?

eza*_*ker 6

从图片中我假设您使用的是jQM版本1.3.x,但此解决方案也适用于1.4.x.

假设你有类似这样的标记:

<fieldset data-role="controlgroup" data-type="horizontal">
    <legend>Font:</legend>
    <input type="radio" name="thefont" id="radio-1" value="arial" checked="checked" />
    <label for="radio-1">Arial</label>
    <input type="radio" name="thefont" id="radio-2" value="verdana" />
    <label for="radio-2">Verdana</label>
    <input type="radio" name="thefont" id="radio-3" value="tahoma" />
    <label for="radio-3">Tahoma</label>
</fieldset>
Run Code Online (Sandbox Code Playgroud)

切换到Tahoma的脚本将是:

$("[name='thefont']").prop( "checked", false ).checkboxradio( "refresh" );
$("#radio-3").prop( "checked", true ).checkboxradio( "refresh" );
Run Code Online (Sandbox Code Playgroud)

第一行取消选中所有框,第二行检查tahoma框.在jQM中,您必须在更改值后刷新checkboxradio小部件.

DEMO