日期:2014-05-16  浏览次数:20470 次

怎么判断多选按纽为空,救救我啊,在线等.马上给分!
怎么用javascript实现判断多选按纽是否为空,谢谢了

------解决方案--------------------
多选按钮是什么?checkbox?
------解决方案--------------------
function abc(n){
var chkbox = document.getElementsByName(n);
for(var i=0; i <chkbox.length; i++){
if(chkbox[i].checked) return true;
}
return false;
}

alert(abc( "CHKBOX "));
------解决方案--------------------
上面代码已给出了啊,把米给你煮熟了吧
<form action= " " method= "post " onsubmit= "return chk(); ">
<input name= "n " type= "checkbox " value= " " />
<input name= "n " type= "checkbox " value= " " />
<input name= "n " type= "checkbox " value= " " />
<input name= " " type= "submit " value= "提交 " />
</form>
<script>
function chk(){
var box=document.getElementsByName( 'n ');
var val=false;
for(var i=0;i <box.length;i++){
if(box[i].checked){
val=true;
break;
}
}
if(val==false){
alert( "未选! ");
return false;
}
}
</script>

试试
------解决方案--------------------
<form action= " " method= "post " onsubmit= "return chk(); ">
<input name= "n " type= "checkbox " value= " " />
<input name= "n " type= "checkbox " value= " " />
<input name= "n " type= "checkbox " value= " " />
<input name= " " type= "submit " value= "提交 " />
</form>
<script>
function chk(){
var box=document.getElementsByName( 'n ');
var count; 选择的个数
for(var i=0;i <box.length;i++){
if(box[i].checked){
count++;
}
}
if(count <1){
alert( "未选! ");
return ;
}
}
</script>

------解决方案--------------------
<form action= " " method= "post " onsubmit= "return chk(); ">
<input name= "n " type= "checkbox " value= " " />
<input name= "n " type= "checkbox " value= " " />
<input name= "n " type= "checkbox " value= " " />
<input name= " " type= "submit " value= "提交 " />
</form>
<script>
function chk(){
var box=document.getElementsByName( 'n ');
var val=false;
for(var i=0;i <box.length;i++){
if(box[i].checked){
val=true;
break;
}
}
if(val==false){
alert( "未选! ");
return false;
}
}
</script>

------解决方案--------------------
使用ID
getElementById()
------解决方案--------------------
根据它的checked属性判断

if(document.getElementById(checkBoxID).checked){
//选中
}else{
//没选中,为空
}