<asp:RadioButton ID="rdoYes" runat="server" GroupName="Sj" Text="是"/>
现在有个单选按钮  要控制一个层的显示和隐藏  JS代码怎么写  

解决方案 »

  1.   

    OnSelectedIndexChanged 在服务端事件中处理,向客户端注册脚本
    或者运行后,用JQuery给rdoYes的子项绑定
    $("<%=rdoYes.ClientID%> > input").click(
       function(){$('#myDiv').toggle();}
    );
      

  2.   

    搞成RadioButtonList去了
    一个的话,直接写客户端事件
      

  3.   

    block 和null 就可以直接设置啊
      

  4.   

    block none  我不知道怎么写了  现在是服务器控件
      

  5.   

     <asp:RadioButton ID="rdoYes" runat="server" GroupName="Sj" Text="是"/>&nbsp;&nbsp;
                <asp:RadioButton ID="rdoNo" runat="server"  Checked="true" GroupName="Sj" Text="否" />
    2个按钮  我不懂Jquery  能给我代码吗   急啊
      

  6.   

    <div id="层隐藏" runat="server" style="display: none"> 
    <div id="层显示" runat="server" style="display: block">
      

  7.   

    后台:
    层隐藏.Style.Add("display", "block");  --显示.
    层显示.Style.Add("display", "none");  --隐藏.
      

  8.   

    可以,$("id").slideToggle('slow'); Jquery这样写.你要用JS就是:
    function checkJiaoyu() {
     判断按钮 获取ID:rdoYes和rdoNo是否为null,
     rdoYes为null:document.getElementById("层id").style.display="none"  --隐藏 
     rdoNo为null:document.getElementById("层id").style.display="block"  --显示 
    }
      

  9.   

    不能判断为null。
    判断为:.checked属性,
    还以为这段代码是判断生成的,只有一个有,另一个为空...
      

  10.   

    用html的标签,别加runat="server"响应客户端事件执行js
      

  11.   


    是的,给你的两个单选按钮都加上一个客户端事件
    <asp:RadioButton ID="rdoYes" runat="server" GroupName="Sj" Text="是" onclick="toggleDiv(true)" />
    <asp:RadioButton ID="rdoNo" runat="server" Checked="true" GroupName="Sj" Text="否" onclick="toggleDiv(false)" />function toggleDiv(isShow){   
       document.getElementById("Div的ID").style.display = isShow ? "block" : "none";
    }
      

  12.   

    把你写的代码贴出来别告诉我你直接用的getElementById("Div的ID")
      

  13.   


    应该是文档DOM还未加载完就点了按钮,呵呵
    把那个function移到</form>后面去
    或者用JQuery $(document).ready(),不过那也不用写那么麻烦了
      

  14.   

    加个容错判断好了function toggleDiv(isShow){   
        if(document.getElementById("Div的ID") == null) return;
        document.getElementById("Div的ID").style.display = isShow ? "block" : "none";
    }
      

  15.   


    不报错了  但是不显示层    <asp:RadioButton ID="rdoYes" runat="server" GroupName="Sj" Text="是" onclick="toggleDiv(true)" />&nbsp;&nbsp;
    <asp:RadioButton ID="rdoNo" runat="server" Checked="true" GroupName="Sj" Text="否" onclick="toggleDiv(false)" />   <div style="display: none;" id="divSJ" runat="server">
         <table id="Table2">
         <tr>
         <td align="left">结束时间:</td>
             <td colspan="3">
                <SharePoint:DateTimeControl ID="dtTime" runat="server">
                </SharePoint:DateTimeControl>
            </td>
            </tr>
            </table>
            </div>function toggleDiv(isShow){   
       if(document.getElementById("Div的ID") == null) return;  document.getElementById("divSJ").style.display = (isShow) ? "block" : "none";
    }
      

  16.   

    documnet。getelementById(“”)里面的id用生成页面之后查看源文件里的那个id
      

  17.   

    可以,$("id").slideToggle('slow'); Jquery这样写.你要用JS就是:
    function checkJiaoyu() {
     判断按钮 获取ID:rdoYes和rdoNo是否为null,
     rdoYes为null:document.getElementById("层id").style.display="none" --隐藏  
     rdoNo为null:document.getElementById("层id").style.display="block" --显示  
    }用radiobuttonlist 
      

  18.   


    <!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 id="Head1" runat="server">
    <title>系统登录</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <script>
        var test = function(temp){
            document.getElementById("div").style.display=temp;
        }
      </script>
    </head>
    <body>
    <form id="login_form" runat="server" method="post">
    <asp:RadioButton ID="rdoYes" runat="server" GroupName="Sj" Text="是" onclick="test('block')"/>
      <asp:RadioButton ID="rdoNo" runat="server" Checked="true" GroupName="Sj" Text="否" onclick="test('none')" />
      <div id="div">div</div>
    </form>
    </body>
    </html>
      

  19.   


    <div style="display: none;" id="divSJ" runat="server">这里你必须得使用服务端的div吗?
    下面那个改了,上面那个怎么不改掉
    <script type="text/javascript">
    function toggleDiv(isShow){
      var myDiv = document.getElementById("<%=divSJ.ClientID%>");
      if(myDiv == null) return;
      myDiv.style.display = (isShow) ? "block" : "none";
    }
    </script>