如题,
下面是客户端生成的HTML代码:
<tr>
<td><input id="rdAdSize_0" type="radio" name="rdAdSize" value="1" />
<label for="rdAdSize_0">728×90</label></td><td>
<input id="rdAdSize_1" type="radio" name="rdAdSize" value="2" />
<label for="rdAdSize_1">160×600</label></td><td>
<input id="rdAdSize_2" type="radio" name="rdAdSize" value="3" />
<label for="rdAdSize_2">200×200</label></td>
</tr><tr>通过js 在客户端得到 728×90 160×600  200×200这些值

解决方案 »

  1.   


    <script type="text/javascript">
    window.alert(document.getElementById("rdAdSize_0").nextSibling.nextSibling.innerText);
    </script>
      

  2.   

    <script type="text/javascript">
    window.alert(document.getElementById("rdAdSize_0").nextSibling.nextSibling.innerText);
    </script>
      

  3.   

    GetChecked.aspx:
    -----------------------------------------
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetChecked.aspx.cs" Inherits="GetChecked" %><!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>Untitled Page</title>    <script type="text/javascript">
        function doSelect(obj,elId){
            var txtArea = document.getElementById(elId);
            var txt = obj.parentNode.attributes["tag"].value;
            var orgtxt = txtArea.value;
            //
            if(orgtxt !=""){
                orgtxt = "," +orgtxt;
            }
            if(obj.checked){
                orgtxt = orgtxt + "," + txt;
            }else{
                orgtxt=  orgtxt.replace("," + txt,"");
            }
            //移出字符串第一个逗号
            orgtxt = orgtxt.replace(",","");
            txtArea.value = orgtxt;
        }
        </script></head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:CheckBoxList ID="CheckBoxList1"
                runat="server">
            </asp:CheckBoxList>
        </div>
        </form>
    </body>
    </html>
    -----------------------------------------GetChecked.aspx.cs:
    -----------------------------------------
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;public partial class GetChecked : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (RepeaterData org in GetRepeaterData())
            {
                ListItem list = new ListItem(org.Name, org.Id);
                list.Attributes["onclick"] = "doSelect(this,'" + this.TextBox1.ClientID + "');";
                list.Attributes["tag"] = org.Name;
                this.CheckBoxList1.Items.Add(list);
            }
        }    protected System.Collections.Generic.List<RepeaterData> GetRepeaterData()
        {
            System.Collections.Generic.List<RepeaterData> list = new System.Collections.Generic.List<RepeaterData>();
            for (int i = 0; i < 10; i++)
            {
                list.Add(new RepeaterData("_name:" + i.ToString(), "_id:" + i.ToString(), "_content:" + i.ToString()));
            }
            return list;
        }    public class RepeaterData
        {
            private string _name;
            private string _id;
            private string _content;        public RepeaterData(string name, string id, string content)
            {
                this._name = name;
                this._id = id;
                this._content = content;
            }        public string Name
            {
                get { return _name; }
            }        public string Id
            {
                get { return _id; }
            }
            public string Content
            {
                get { return _content; }
            }
        }
    }
    -----------------------------------------
      

  4.   

    同意一楼的!
    不过我不清楚你为什么这样!
     你的方法:
     <tr>
                <td>
                    <input id="rdAdSize_0" type="radio" name="rdAdSize" value="1" />
                    <label for="rdAdSize_0">
                        728×90 
                    </label>
                </td>
                <td>
                    <input id="rdAdSize_1" type="radio" name="rdAdSize" value="2" />
                    <label for="rdAdSize_1">
                        160×600
                    </label>
                </td>
                <td>
                    <input id="rdAdSize_2"  type="radio" name="rdAdSize" value="3" />
                    <label for="rdAdSize_2">
                        200×200
                    </label>
                </td>
            </tr>
    建议使用:
            <tr>
                <td>
                    <asp:RadioButton ID="RadioButton4" runat="server" Text="728×90" />
                </td>
                <td>
                    <asp:RadioButton ID="RadioButton5" runat="server" Text="160×600" GroupName="RadioButton1" />
                </td>
                <td>
                    <asp:RadioButton ID="RadioButton6" runat="server" Text="200×200" GroupName="RadioButton1" />
                </td>
            </tr>
      

  5.   

    把你要的内容放在控件上方便很多!        <tr>
                <td>
                    <asp:RadioButton ID="RadioButton4" runat="server" Text="728×90" />
                </td>
                <td>
                    <asp:RadioButton ID="RadioButton5" runat="server" Text="160×600" GroupName="RadioButton4" />
                </td>
                <td>
                    <asp:RadioButton ID="RadioButton6" runat="server" Text="200×200" GroupName="RadioButton4" />
                </td>
            </tr>
     
      

  6.   

    <script type="text/javascript">
    window.alert(document.getElementById("rdAdSize_0").nextSibling.innerText);
    </script>
      

  7.   

    错了,应该是
    <script type="text/javascript"> 
    window.alert(document.getElementById("rdAdSize_0").nextSibling.innerHTML); 
    </script>