如题 我想问下 用RadioButtonList 如何控制div的隐藏于显示
用JavaScript写的 不是写在后台的 有办法吗?

解决方案 »

  1.   

    RadioButtonList 跟DIV有啥关系啊,具体业务是什么啊
    问问题写详细点啊
      

  2.   

    window.onload=function() 

      var div=document.getElementById("div1") 
      div.style.display=div.style.display=="none"?"block":"none"; 
    }
    Page.RegisterStartUpScript("key",@"getElementById('div').style.display = 'none';") <div id="div1" runat="Server"> </div> 
    div1.Style["Display"] = "Block"; //显示
    div1.Style["Display"] = "None"; //隐藏
      

  3.   

    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem onclick="showDivByID(1);">1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
        <asp:ListItem>4</asp:ListItem>
        </asp:RadioButtonList>function showDivByID(index)
        {
            document.getElementById("div" + index).style.display = "block";
        }
      

  4.   

    前台代码:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Test.WebForm1" %><!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" onchange="showDiv();" AutoPostBack="true" 
            onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
            <asp:ListItem Value="1">第一个</asp:ListItem>
            <asp:ListItem Value="2">第二个</asp:ListItem>
            <asp:ListItem Value="3">第三个</asp:ListItem>
        </asp:RadioButtonList>
        <div id="div1" style="display:none;background-color:Gray;">
            我是DIV
        </div>
        </form>
    </body>
    </html>
    后台代码:
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
            {
                int i = RadioButtonList1.SelectedIndex;
                if (i % 2 == 0)
                {
                    Page.RegisterStartupScript("showDiv", "<script>document.getElementById('div1').style.display='inline';</script>");
                }
                else
                {
                    Page.RegisterStartupScript("showDiv", "<script>document.getElementById('div1').style.display='none';</script>");
                }
            }
      

  5.   

    display="none"隐藏
    display="block"显示