【发布时间】:2011-06-22 01:00:16
【问题描述】:
我正在做一个表单,其中用户有一个选项列表。一些单选按钮,一些复选框。用户可能是一厢情愿的,会改变主意。我需要更改输入和类中的检查值,因此我可以通过表单提交来定位这些值。这需要在用户单击提交之前发生。这是我到目前为止所拥有的,它更改了“已检查”属性和类,但是一旦不再选择按钮,它们就不会变回来。救命!
$("input:checkbox, input:radio").change(function() {
if ($("input:checked")) {
$(this).attr("checked",true);
$(this).addClass("checked");
} else {
$(this).attr("checked",false);
$(this).removeClass("checked");
}
});
更新:仍然没有。我已将其缩减为以下内容,但它仍然没有删除更改类。
$("input:checkbox, input:radio").change(function ()
{
if (this.checked)
{
$(this).addClass("checked");
}
else
{
$(this).removeClass("checked");
}
});
【问题讨论】:
标签: jquery attributes checkbox radio-button