我使用jQuery 1.4.3如何按类和属性值过滤掉?
我有几个输入看起来像这样的:
<input type='checkbox' id='1' class='Product' comp='1'>
<input type='checkbox' id='2' class='Product' comp='1'>
<input type='checkbox' id='3' class='Product' comp='1'>
<input type='checkbox' id='4' class='Product' comp='2'>
<input type='checkbox' id='5' class='Product' comp='2'>
<input type='checkbox' id='6' class='Product' comp='2'>
如果与产品类的盒子被点击我想它的价值补偿和取消选中其他框具有不同的补偿值。
通常情况下,我会遍历和检查每个补偿值,然后取消在必要时,这样的伪代码:
ThisComp == 1 // comp value of checkbox that was just clicked
$(".Product").each(function() {
var Comp $(this).attr("comp");
if (ThisComp != Comp) {
// $(this).attr("checked", false);
}
});
我想知道是否有一种方法在选择使用补偿值过滤,像这样的伪代码:
$(".Product comp=2").attr("checked", false);
这里的目标是取消选中具有比一个有效率的方式点击不同的补偿值的任何框。
'id'值不应以数字开头。 – 2012-02-07 18:58:31
您可能想要将该属性重命名为“data-comp”。数据属性自动绑定到'element.dataset'和jQuery的'.data()'。 – 2012-02-07 19:06:24