javascript获得CheckBoxList选中的数量
2009-10-27 00:00
507 查看
jQuery的选择器真的好强大,好灵活。 javascript的原始方法也值得研究。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckBoxList.aspx.cs" Inherits="CheckBoxList" %> <!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 runat="server"> <title>获得CheckBoxList选中的数量(jQuery与Javascript对照学习/前台与后台)</title> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript"> //jQuery的方法(王君) $(function(){ $("#chkBox").click(function(){ alert($("#chkBox input[@type=checkbox]:checked").size()); }); }); //javacript方法(候林) function f(){ var a=document.getElementsByTagName('input') var num=0; for(var i=0;i<a.length;i++){ if(a[i].type=='checkbox'){ if(a[i].checked==true) num+=1; } } alert(num); } </script> </head> <body> <form id="form1" runat="server"> <div> jQuery的选择器真的好强大,好灵活。<br /> javascript的原始方法也值得研究。 </div> <div> <input type="button" value="Javascript取值" onclick="f();" /> <asp:CheckBoxList ID="chkBox" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:CheckBoxList> <asp:Button ID="btnOk" runat="server" OnClick="btnOk_Click" Text="服务器端取" /> </div> </form> </body> </html>
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class CheckBoxList : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnOk_Click(object sender, EventArgs e) { int totalNum = 0;//总数 string list = "000";//选中的值 for (int i = 0; i < this.chkBox.Items.Count; i++) { if (chkBox.Items[i].Selected) { totalNum += 1; list += "," + chkBox.Items[i].Value; } } Response.Write(totalNum.ToString() + "|" + list); } }
相关文章推荐
- javascript获得CheckBoxList选中的数量(jQuery与Javascript对照学习/前台与后台)
- javascript获得CheckBoxList选中的数量
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组(转)
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组
- 限制CheckBoxList选中的数量
- 使用JavaScript获得checkbox选中项
- 限制CheckBoxList选中的数量
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组
- CheckBoxList多选,获得选中的值!
- jquery 怎么获得checkboxList 选中的值
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组
- javascript checkbox 赋值选中
- CheckBox控件默认选中,提交时永远获得选中状态的实现代码
- checkbox全选/取消/选中所有奇数/反选/获得选中的值
- 利用 JavaScript 去限制 CheckBoxList 的勾選數
- Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中