【发布时间】:2014-02-20 11:29:42
【问题描述】:
我在我的项目中使用以下 Jquery 按钮集:
<div id="TR1_Mode">
<input type="radio" id="TR1_Mode_Dif" name="TR1_Mode_radio" value="Mode_Dif" ><label for="TR1_Mode_Dif">Differentiation</label>
<input type="radio" id="TR1_Mode_Int" name="TR1_Mode_radio" value="Mode_Int" checked="checked"><label for="TR1_Mode_Int">Integration</label>
</div>
使用以下代码以编程方式更改“已检查”状态(在控制台中尝试过):
$('[name="TR1_Mode_radio"][value="Mode_Dif"]').attr("checked", false);
$('[name="TR1_Mode_radio"][value="Mode_Int"]').attr("checked", true);
$('#TR1_Mode').buttonset("refresh");
它可能会起作用,但是在反过来做同样的事情之后:
$('[name="TR1_Mode_radio"][value="Mode_Dif"]').attr("checked", true);
$('[name="TR1_Mode_radio"][value="Mode_Int"]').attr("checked", false);
$('#TR1_Mode').buttonset("refresh");
选中的按钮将变为未选中状态,但未选中的按钮不会变为选中状态。我是否遗漏了什么或者这是 jquery 中的不当行为?
检查按钮似乎表现良好,但它们并不能实现相同的目的。
我使用 Chrome (32.0.1700.107 m) 和 Firefox (27.0.1) 进行了测试,并使用最新的 Jquery 版本进行了测试:jquery-2.0.3.js 和 jquery-1.10.2.js
【问题讨论】:
-
尝试 $('[name="TR1_Mode_radio"][value="Mode_Int"]').removeAttr("checked") 而不是 attr("checked", false)
标签: javascript jquery html refresh radio