C#中javascript如何在后台或者多选框的值
publicpartialclasscheckbox:System.Web.UI.Page{protectedvoidPage_Load(objectsender,Eve...
public partial class checkbox : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { string con = ConfigurationSettings.AppSettings["myconection"]; string select = "select name from ID"; string str = string.Empty; SqlConnection conn = new SqlConnection(con); SqlDataAdapter myda = new SqlDataAdapter(select,conn); DataTable mydt = new DataTable(); conn.Open(); try { DataSet myds = new DataSet(); myda.Fill(myds); mydt = myds.Tables[0]; for (int i = 0; i <mydt.Columns.Count; i++) { foreach(DataRow dr in mydt.Rows) { str += "<input type=checkbox value='"+dr[i]+"'>'"+dr[i]+"'<p>"; } } str += "<input type=button value='确定' id='button'>"; Response.Write(""); } finally { conn.Close(); Label1.Text = str; } } } } 这个是我写的多选框都是写在后台的 我现在想在点击BUTTON按扭后获得选定的值 应该怎么办
展开
1个回答
展开全部
str += "<input type=checkbox name=\"cname\" value='"+dr[i]+"'>'"+dr[i]+"'<p>"; js: var cname = document.getElementsByName("cname"); for(var j=0;j<cname.length;j++) { e = cname[j]; if(e.checked == false) { alert(cname[j].value);} }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询