如何删除checked =" checked"用于未经检查的jQuery复选框? [英] How to remove checked="checked" for unchecked checkboxes with jQuery?
本文介绍了如何删除checked =" checked"用于未经检查的jQuery复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我目前的剧本
<script>
$().ready(function(){
$('.prettycheckbox').click(function () {
$('.prettycheckbox input').removeAttr('checked');
$('.prettycheckbox a').removeClass('checked');
$("a", this).addClass('checked');
$("input", this).addAttr("checked");
});
});
</script>
但是效果不好,因为添加和删除链接类的部分效果很好,但对于输入它不起作用。
But it's not working well, bceause the part with adding and removing class to links works nice , but for input it doesn't work.
如何使选中复选框如下所示:
How to make the "checked" checkbox looks like this:
<input class="payment_type" type="checkbox" value="1" name="payment_type" style="display: none;" checked="checked">
和所有其他人看起来像这样?:
and all others look like this?:
<input class="payment_type" type="checkbox" value="1" name="payment_type" style="display: none;">
怎么做?像使用jquery和复选框的输入无线电类型?
How to do that? Something like input radio type using jquery and checkboxes?
推荐答案
在,
要更改复选框的属性,您应该使用 .prop()
功能。
To change the property of checkbox you should use the .prop()
function.
$('.prettycheckbox input').prop('checked', false);
$('.prettycheckbox input').prop('checked', true);
jQuery 1.5及以下
.prop()
功能不存在,但 .attr()
类似:
jQuery 1.5 and below
The .prop()
function doesn't exist, but .attr()
does similar:
$('.prettycheckbox input').attr('checked', 'checked');
注意: removeAttr
有效,但 addAttr
不是。
这篇关于如何删除checked =" checked"用于未经检查的jQuery复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文