jQuery Mobile-以编程方式更改单选按钮状态
jQuery Mobile - Change radiobutton state programmatically
在水平控制组中有此单选按钮:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Geslacht:</legend>
<input id="gender-male" name="gender" type="radio" value="MALE" />
<label for="gender-male">Man</label>
<input id="gender-female" name="gender" type="radio" value="FEMALE" />
<label for="gender-female">Vrouw</label>
</fieldset>
</div>
在给定的点上,我想通过编程重置值,使用:
$('#gender-male').prop('checked', false)
$('#gender-female').prop('checked', false)
但是,单选按钮的样式没有改变。
例如,如果选择了MALE,则它仍然显示为已选择。
我应该刷新一下吗?
看看这个:
$('#gender-male').attr("checked",false).checkboxradio("refresh");
JqueryMobile 1.4的工作解决方案(已测试)如下:
(html取自JQM 1.4演示代码)
<form><fieldset data-role="controlgroup">
<input type="radio" name="radio-choice-v-2" id="radio-choice-v-2a" value="on" checked="checked">
<label for="radio-choice-v-2a" style="font-weight: 100;">radio button A</label>
<input type="radio" name="radio-choice-v-2" id="radio-choice-v-2b" value="off">
<label for="radio-choice-v-2b" style="font-weight: 100;">radio button B</label>
</fieldset></form>
如上所述,选中单选按钮A。您要将单选按钮B设置为选中,将A设置为未选中。请注意:复选框xradio("刷新")用于每个单选按钮。
Javascript/Jquery(取自JQM 1.4 API文档并重新改编)
if (radioSetting == 0) {
$( "#radio-choice-v-2b" ).prop( "checked", false ).checkboxradio( "refresh" );
$( "#radio-choice-v-2a" ).prop( "checked", true ).checkboxradio( "refresh" );
}
else {
$( "#radio-choice-v-2a" ).prop( "checked", false ).checkboxradio( "refresh" );
$( "#radio-choice-v-2b" ).prop( "checked", true ).checkboxradio( "refresh" );
}
相关文章:
- MVC和JQuery Mobile:单选按钮在发布时释放状态
- 如何重置剑道MVVM单选按钮's已检查状态
- Angularjs 单选按钮变为多个选定状态
- 如何更新单选按钮的状态以匹配转盘状态
- jQuery识别页面加载上的单选按钮的不正确状态,当单选值=“0”时;否”;并且两个无线电都没有被选择
- 统一JS单选按钮不更改状态
- 通过单选按钮状态设置HTML元素的可见性
- 更改单选按钮状态时更改标题
- 如何使单选按钮在选择一个选项(CSS)后显示为选中状态
- 为什么可以't键入文本输入时,单选按钮保持选中状态
- 基于单选按钮状态的角度JS高亮显示行
- 如何使用JavaScript设置单选按钮状态
- jQuery Mobile-以编程方式更改单选按钮状态
- 基于单选按钮状态的链接点击动态生成href: PHP与javascript的交互
- jQuery缓存刷新复选框单选按钮状态
- 使用javascript访问单选按钮状态
- 单选按钮状态在鼠标上升或点击时没有更新
- 根据从 Angular JS 中的 REST 接收的值设置单选按钮状态
- 在更改单选按钮状态时显示提交按钮.如何
- 使用JQuery更改单独的单选按钮状态和运行相关功能