日期:2014-05-17  浏览次数:20630 次

.net页面上有三个RadioButton(服务器控件),控制下面三个层的隐藏和显示,也就是选中一个隐藏另外两个
第一个RadioButton是默认选中的, 通过js或jquery方法实现。

------解决方案--------------------
var rA=document.getElementById("rbtnA");
var divA=document.getElementById("divA");
if(rA.checked){
divA.style.display='block';
}else{
divA.style.display='none';
}
给你一个思路,无论是3个或者多个都是这样做的
------解决方案--------------------
HTML code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
    <script type="text/javascript">
        $(function () {
            $(".rb :input").bind("click", function (event) {
                var senderIndex = $(".rb :input").index($(this));
                //alert(senderIndex);
                $(".mydiv").hide();
                $($(".mydiv").get(senderIndex)).show();
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:RadioButton CssClass="rb" GroupName="rb" ID="rb01" runat="server" Text="rb01"  Checked="true"/>
    <asp:RadioButton CssClass="rb" GroupName="rb" ID="rb02" runat="server" Text="rb02" />
    <asp:RadioButton CssClass="rb" GroupName="rb" ID="rb03" runat="server" Text="rb03" />
    </div>
    <div class="mydiv">mydiv01</div>
    <div class="mydiv" style=" display:none">mydiv02</div>
    <div class="mydiv" style=" display:none">mydiv03</div>
    </form>
</body>
</html>

------解决方案--------------------
<asp:RadioButton ID="rbtnHour" GroupName="cyc" Text="按时" runat="server" onclick="radio_class('1','true')" />
<asp:RadioButton ID="rbtnDay" GroupName="cyc" Text="按天" runat="server" onclick="radio_class('2','true')" />
<asp:RadioButton ID="rbtnWeek" GroupName="cyc" Text="按周" runat="server" onclick="radio_class('3','true')" />
<asp:RadioButton ID="rbtnMonth" GroupName="cyc" Text="按月" runat="server" onclick="radio_class('4','true')" />
<asp:RadioButton ID="rbtnYear" GroupName="cyc" Text="按年" runat="server" onclick="radio_class('5','true')" />
<asp:RadioButton ID="rbtnClass" GroupName="cyc" Text="轮班" runat="server" onclick="radio_class('6','true')" />


 function radio_class(onvalue, flag) {
//只有轮班的时候才隐藏
document.getElementById('pFinish').style.display = "";
if (onvalue == 1) {
document.getElementById('aa').style.display = "";
document.getElementById('bb').style.display = "none";
document.getElementById('cc').style.display = "none";
document.getElementById('dd').style.display = "none";
document.getElementById('ee').style.display = "none";
document.getElementById('ff').style.display = "none";