【发布时间】:2013-08-07 19:21:08
【问题描述】:
这是我当前的脚本
<script>
$().ready(function(){
$('.prettycheckbox').click(function () {
$('.prettycheckbox input').removeAttr('checked');
$('.prettycheckbox a').removeClass('checked');
$("a", this).addClass('checked');
$("input", this).addAttr("checked");
});
});
</script>
但是效果不好,因为在链接中添加和删除类的部分效果很好,但是对于输入它不起作用。
如何使“选中”复选框看起来像这样:
<input class="payment_type" type="checkbox" value="1" name="payment_type" style="display: none;" checked="checked">
其他的都这样吗?:
<input class="payment_type" type="checkbox" value="1" name="payment_type" style="display: none;">
如何做到这一点?类似于使用 jquery 和复选框的输入单选类型?
【问题讨论】:
-
方法是
.attr( "checked", "checked" ),但这不是你想要的,因为属性"checked"引用.defaultChecked属性,你想改变.checked。更改.defaultChecked属性或"checked"属性只有在用户尚未触摸复选框时才会生效。 -
由于某种原因,这是有效的;D
$('.prettycheckbox input').removeAttr('checked'); $('.prettycheckbox a').removeClass('checked'); $("a", this).addClass('checked'); $("input", this).attr("checked", true);
标签: jquery