我的都选要求只能选取3个答案,该如何写
解决方案 »
- 求解释,each(forEach)函数,实在看不懂
- myeclipse提示Multiple markers at this line是什么意思?
- 怎么在每个div处点击后都显示在屏幕的正中间啊?
- 请问apply方法的第一个参数为null是什么意思?
- 100分 求助 JS 调用 exe
- 你好,刚才用你的方法在IE下可以运行了,可是我发现在firefox下没有响应了.能否再给你帮助?
- 刷新问题怎么解决啊?
- 为什么这样的呢
- 请问加载页面时提示“正在装载页面,请稍候”是怎么实现的,请给个例子
- 如何动态加载文本框的内容到指定的div中,就像QQ聊天窗口一样。。。。。
- 象邮件中增加一个附件的JS问题
- 关于网站快捷通道的实现方法?
var j=0;
for(var i=0;i<objs.length;i++)
{
if(objs[i].checked)
j++;
}
if(parseInt(j)>3)
{
alert("错误")
}
<script>
var max =3
var j = 0;
function chk(obj1){
var obj = document.getElementsByName(obj1.name);
if(obj1.checked){
j++;
if(j==max){
for (i = 0; i < obj.length; i++){
if(obj[i].checked==false){
obj[i].disabled=true;
}
}
}
}
else{
j--;
for(var i=0;i<obj.length;i++){
if(obj[i].disabled==true){
obj[i].disabled=false;
}
}
}
}
</script>
<INPUT type="checkbox" name="uid1" value="1" onClick="chk(this);">
<INPUT type="checkbox" name="uid1" value="2" onClick="chk(this);">
<INPUT type="checkbox" name="uid1" value="3" onClick="chk(this);">
<INPUT type="checkbox" name="uid1" value="4" onClick="chk(this);">
<INPUT type="checkbox" name="uid1" value="5" onClick="chk(this);">
<!--
function check_form(fN){
for(var i=1;i<=3;i++){
if(i==1) if(!maxSelected(fN,i,2)) return false;//第1题限选2项
if(i==3) if(!maxSelected(fN,i,3)) return false;//第3题限选3项
}
alert('提交!');
}function maxSelected(fN,qN,max){
var objQ = eval('document.'+fN+'.q'+qN),selectedN=0;
if(objQ && objQ.length){
if(objQ.length<=max) return true;
else{
for(var i=0;i<objQ.length;i++) if(objQ[i].checked) selectedN++;
if(selectedN>max) {alert('题目 '+qN+' 限选 '+max+' 项');objQ[0].focus();return false;}
else return true;
}
}
}
</script>
<form name="question" style="font-size:12px;">
1.题目一:(限选两项)<br>
<input type="checkbox" name="q1" value="1" checked>1111
<input type="checkbox" name="q1" value="2">2222
<input type="checkbox" name="q1" value="3" checked>3333
<input type="checkbox" name="q1" value="4">4444
<input type="checkbox" name="q1" value="5" checked>5555
<input type="checkbox" name="q1" value="61">6666<br><br>
2.题目二:<br>
<input type="checkbox" name="q2" value="1">aaa
<input type="checkbox" name="q2" value="2">bbb
<input type="checkbox" name="q2" value="3">ccc
<input type="checkbox" name="q2" value="4">ddd
<input type="checkbox" name="q2" value="5">eee
<input type="checkbox" name="q2" value="61">fff<br><br>
3.题目二:(限选三项)<br>
<input type="checkbox" name="q3" value="1" checked>AA
<input type="checkbox" name="q3" value="2" checked>BB
<input type="checkbox" name="q3" value="3" checked>CC
<input type="checkbox" name="q3" value="4">DD
<input type="checkbox" name="q3" value="5" checked>EE
<input type="checkbox" name="q3" value="6">FF<br><br>
<input type="button" onclick="check_form('question')" value="提交">
</form>
if(objQ.length<=max) return true;改为:if(objQ.length==max) return true;if(selectedN>max) {alert('题目 '+qN+' 限选 '+max+' 项');objQ[0].focus();return false;}改为:
if(selectedN!=max) {alert('题目 '+qN+' 限选 '+max+' 项');objQ[0].focus();return false;}
var max = 3
function chk(obj1){var obj = document.getElementsByName(obj1.name);var j = 0;
if (obj.length){
for (i = 0; i < obj.length; i++){
if (obj[i].checked) j++;
if (j > max){
alert("对不起,只能选取"+ max +"。");
obj1.checked = false ;
break;
}
}
}
}</script>这个代码又该如何改呢?
var j=0;
for(var i=0;i<objs.length;i++)
{
if(objs[i].checked)
j++;
}
if(parseInt(j)!=3)
{
alert("错误")
}
var j=0;
for(var i=0;i<objs.length;i++)
{
if(objs[i].checked)
j++;
}
if(j!=3)
{
alert("错误")
}
var obj = document.getElementById("aaaa");
if(obj.length<3){
alert("所选择的数量小于3");
}