怎么样用javascript实现在ASP.NET 中
选中两个单选按钮实现文本框的显示和隐藏

解决方案 »

  1.   

    如果是js控制客户端文本框就简单.
    <input type="check" onclick="document.getElementById('text1').style.dispaly=this.checked?'':'none';" />隐藏
    <input type="text" id="text1" />如果是控制服务器端textbox
    default.aspx
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!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></title>
        <script>
        function tst(obj)
        {
        //像上面的写法,不写function,直接写到checkbox的onclick事件里也一样.
                 document.getElementById("<%=txtClientStr%>").style.display=obj.checked?"none":"";
            
        }</script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="checkbox" onclick="tst(this)" /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
        </form>
    </body>
    </html>
    default.aspx.cs
    public partial class _Default : System.Web.UI.Page 
    {
        public string txtClientStr;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.txtClientStr = TextBox1.ClientID;
        }
    }