日期:2014-05-18  浏览次数:20395 次

如何用脚本判断ASP.NET中的服务器控件CheckBoxList是否被选中?急急急急急急急————————在线等
RT

------解决方案--------------------
document.getElementById( "** ").checked
------解决方案--------------------
var eles = document.form1.cbl
var check=false;
for(var i=0;i <eles.length;i++)
{
if(eles[i].checked)
{
check=true;
}
}
------解决方案--------------------
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script type= "text/javascript ">
function Choose()
{
var inputs = document.all.tags( "INPUT ");
for (var i = 0; i < inputs.length; i++)
{
if (inputs[i].type == "checkbox " && inputs[i].id.indexOf( "CheckBoxList1 ") > = 0 )
{
if(inputs[i].checked)
{
alert(inputs[i].id);
break;
}
}
}
}

</script>
</head>
<body >
<form id= "form1 " runat= "server ">
<asp:CheckBoxList ID= "CheckBoxList1 " runat= "server " RepeatDirection= "Horizontal ">
<asp:ListItem> aa </asp:ListItem>
<asp:ListItem> bb </asp:ListItem>
</asp:CheckBoxList>
<input id= "Button1 " type= "button " value= "button " onclick= "Choose(); "/>
</form>
</body>
</html>
------解决方案--------------------
.aspx
---------------------
<asp:CheckBoxList ID= "CheckBoxList1 " runat= "server ">
<asp:ListItem> BB </asp:ListItem>
<asp:ListItem> AA </asp:ListItem>
<asp:ListItem> CC </asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "Button " />

.cs
---------------------
protected void Page_Load(object sender, EventArgs e)
{
System.Text.StringBuilder str = new System.Text.StringBuilder();
for(int i = 0;i <this.CheckBoxList1.Items.Count;i++)
{
str.Append( "!document.getElementById( ' " + this.CheckBoxList1.ClientID + "_ " + i + " ').checked && ");
}
if (str.Length > 0)
{
this.Button1.Attributes[ "onclick "] = "if( " + str.Remove(str.Length - 3, 3) + "){return false;}else{return true;} ";
}
else
{
this.Button1.Attributes[ "onclick "] = "window.alert( '啥也没有!... ');return false; ";
}
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write( "你选择了我再做服务端处理... ");
}


------解决方案--------------------
这个一搜 能搜一箩筐
------解决方案--------------------
帮你顶一个