日期:2014-05-19  浏览次数:20464 次

N个checkbox,如何在提交时判断至少选1个。。。
1个button,若干个checkbox,点击按钮时候,怎么来实现至少选择1项???



------解决方案--------------------
js
for(var i=0;i <document.all.length;i++)
{

if(document.all(i).tagName == "INPUT " && document.all(i).type == "checkbox "&&document.all(i).checked==true)
{

v = document.all(i).value;
document.getElementById( "hkid ").value=document.getElementById( "hkid ").value+v+ ", ";



}


}
------解决方案--------------------
var chkvalue = document.getElementById( 'checkbox的ID ').value
if (chkvalue == ' ')
{
return false;
}else{
return true;
}
------解决方案--------------------
function check(Msg)
{
var es = document.form1.elements;//Form1改成你的Form
var count = 0;
for (i=0;i <es.length;i++)
{
var e = document.form1.elements[i];
if (e.type== 'checkbox ' && e.checked == true)
{
count ++;
}
}
if (count == 0)
{
alert( "请选择要操作的记录 ");
return false;
}
else
{
if(confirm(Msg))
{
return true;
}
else
{
return false;
}
}
}

------解决方案--------------------
在js脚本遍历控件,可寻找带有chebox的类似的对像。
然后看该控件是否选择。可用一个计数器来统计.

------解决方案--------------------
bool i = false;
System.Web.UI.ControlCollection con = Page.Controls[0].Controls;
for(int i=0;i <con.Count;i++)
{
if(con[i].GetType==System.Type.GetType( "CheckBox ")
{
if(((CheckBox)con[i]).Checked)
{
i = true;
break;
}
}
}

大致是这样 你看下