<input type='checkbox' name='type' value='运费'/>
<input type='checkbox' name='type' value='加工费'/>
<input type='checkbox' name='type' value='运费'/>
<input type='checkbox' name='type' value='加工费'/>
<input type='checkbox' name='type' value='运费'/>
<input type='checkbox' name='type' value='产品'/>
<input type='checkbox' name='type' value='产品'/>
value会有三种类型:运费、产品、加工费。
如何判断 如果选中一个运费的时候,不能再选 加工费跟产品,必须所有的选项都是运费。
产品跟加工费可以混着选,但运费不能跟产品或者加工费混着选。
运费<input type='checkbox' name='type' value='运费' onclick="return fn(this)"/>
加工费<input type='checkbox' name='type' value='加工费' onclick="return fn(this)"/>
运费<input type='checkbox' name='type' value='运费' onclick="return fn(this)"/>
加工费<input type='checkbox' name='type' value='加工费' onclick="return fn(this)"/>
运费<input type='checkbox' name='type' value='运费' onclick="return fn(this)"/>
产品<input type='checkbox' name='type' value='产品' onclick="return fn(this)"/>
产品<input type='checkbox' name='type' value='产品' onclick="return fn(this)"/>var obj = {}
function fn(self){
var _value = self.value;
if (self.checked){
if (obj[_value]) {
alert("不能重复选择相同选项")
return false;
} else {
obj[_value] = "1";
}
} else {
obj[_value] = null;
}
}
功能实现了,不过楼主这样的需求有问题吧,正常场景是不会出现相同的复选框的,为何不从设计入手?