<input type='checkbox' name='zzfm[]' value='他人介绍 口碑' />他人介绍、口碑
<input type='checkbox' name='zzfm[]' value='价格 优惠活动' />价格、优惠活动
<input type='checkbox' name='zzfm[]' value='商家规模' />商家规模
<input type='checkbox' name='zzfm[]' value='样品品质' />样品品质
<input type='checkbox' name='zzfm[]' value='过场 无要求' />过场,无要求
<input type='checkbox' name='zzfmqita' value='1' />其它(请说明)<input type='text' name='zzfmqitatext' disabled='disabled' value='' />表单元素如上,如何判断,让checkbox最多只能选中其中2个,
如果选中数已经达到2个,剩余没选中的元素设置为不可用状态,
最后一个name=zzfmqita的复选框为一个开关,如果选中的情况下,让后面的文本框为可用状态
<input type='checkbox' name='zzfm[]' value='价格 优惠活动' />价格、优惠活动
<input type='checkbox' name='zzfm[]' value='商家规模' />商家规模
<input type='checkbox' name='zzfm[]' value='样品品质' />样品品质
<input type='checkbox' name='zzfm[]' value='过场 无要求' />过场,无要求
<input type='checkbox' name='zzfmqita' value='1' />其它(请说明)<input type='text' name='zzfmqitatext' disabled='disabled' value='' />表单元素如上,如何判断,让checkbox最多只能选中其中2个,
如果选中数已经达到2个,剩余没选中的元素设置为不可用状态,
最后一个name=zzfmqita的复选框为一个开关,如果选中的情况下,让后面的文本框为可用状态
<input type='checkbox' name='zzfmqita' value='1' />肯定算上"其它"了
<div id="_form" onclick="show()">
<input type='checkbox' name='zzfm[]' value='他人介绍 口碑' />他人介绍、口碑
<input type='checkbox' name='zzfm[]' value='价格 优惠活动' />价格、优惠活动
<input type='checkbox' name='zzfm[]' value='商家规模' />商家规模
<input type='checkbox' name='zzfm[]' value='样品品质' />样品品质
<input type='checkbox' name='zzfm[]' value='过场 无要求' />过场,无要求
<input type='checkbox' name='zzfmqita' value='1' />其它(请说明)<input type='text' name='zzfmqitatext' disabled='disabled' value='' />
</div>
<script>
function show(){
var ops=document.getElementById("_form").getElementsByTagName("input");
var sum=0;
for(var i=0;i<ops.length-1;i++){
if(ops[i].type="checkbox"&&ops[i].checked){sum+=1;}
}
if(sum==2){
for(i=0;i<ops.length-1;i++){
if(ops[i].type="checkbox"&&!ops[i].checked){ops[i].setAttribute("disabled","disabled");}
}
}
}</script>
if(ops[ops.length-1].checked){ops[ops.length].removeAttribute("disabled")}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div>
<input type='checkbox' name='zzfm' value='他人介绍 口碑' />他人介绍、口碑
<input type='checkbox' name='zzfm' value='价格 优惠活动' />价格、优惠活动
<input type='checkbox' name='zzfm' value='商家规模' />商家规模
<input type='checkbox' name='zzfm' value='样品品质' />样品品质
<input type='checkbox' name='zzfm' value='过场 无要求' />过场,无要求
<input type='checkbox' name='zzfmqita' value='1' />其它(请说明)<input type='text' name='qitatext' disabled='disabled' value='' />
</div>
<script type="text/javascript">
var chked = 0;
$("input[name*='zzfm']").click(function() {
var clickchk = $(this)[0];
if (!clickchk.checked) {
chked--;
$("input[name*='zzfm']").each(function() {
$(this).removeAttr("disabled");
});
}
else {
chked++;
}
if (chked == 2) {
$("input[name*='zzfm']").each(function() {
if (!$(this)[0].checked)
$(this).attr("disabled", 'disabled');
});
}
});
$("input[name='zzfmqita']").click(function() {
if ($(this)[0].checked) {
$("input[name='qitatext']").removeAttr("disabled");
}
else {
$("input[name='qitatext']").attr("disabled", 'disabled');
}
});
</script></body>
</html>