日期:2014-05-17 浏览次数:20405 次
<script type="text/javascript" language="javascript"> function CheckGoods(form) { var cb=document.getElementsByTagName("input"); var lb=document.getElementById("lb_totallMoney"); //将数据传给它 var lb2=document.getElementById("lb_GoodPrice"); //绑定数据的Label for(i=0;i<cb.length;i++) { if(cb[i].type=="checkbox"&&cb[i].name=='CheckBox1') { if(cb[i].checked) { lb.innerText="123"; //这样可以 点击复选框后 lb的值会变成 123 lb.innerText=lb2.inner.Text; //这样不行 点击复选框后 lb的值不变 } } } } </script>
<%@ Page Language="C#" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser"); System.Data.DataRow dr; dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32))); dataTable1.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String))); dataTable1.PrimaryKey = new System.Data.DataColumn[] { dataTable1.Columns["UserId"] }; for (int i = 0; i < 8; i++) { dr = dataTable1.NewRow(); dr[0] = i; dr[1] = "【孟子E章】" + i.ToString(); dataTable1.Rows.Add(dr); } DataList1.DataSource = dataTable1; DataList1.DataBind(); } protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { CheckBox CheckBox1 = e.Item.FindControl("CheckBox1") as CheckBox; Label Label1 = e.Item.FindControl("Label1") as Label; CheckBox1.Attributes.Add("onclick", "document.getElementById('" + Label2.ClientID + "').innerHTML=document.getElementById('" + Label1.ClientID + "').innerHTML"); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound"> <ItemTemplate> <div> <asp:CheckBox ID="CheckBox1" runat="server" /> <asp:Label ID="Label1" runat="server"> <%#Eval("UserName")%> </asp:Label> </div> </ItemTemplate> </asp:DataList> <asp:Label ID="Labe