2011-11-03 56 views
0

我有一个情况下,我必须表明基于复选框选择/隐藏div标签。下面是代码示例隐藏/显示Div标签选择价值

<asp:RadioButtonList ID="ckbRestaurent" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" > 
    <asp:ListItem selected="true" Value="0">No</asp:ListItem> 
    <asp:ListItem Value="1">Yes</asp:ListItem> 
</asp:RadioButtonList> 

<div id="xyz"> something.. </div> 

我尝试了几种方法,但它没有工作,因为我是新来的jQuery,我将不胜感激,如果有人给我一个工作的例子上面的代码。

应该通过在页面加载和显示DIV默认隐藏的div当用户选择在RadioButtonList

回答

2

因为我想在我的问题中使用确切的HTML显示解决方案。所以,我发现了一个解决方案,它是作为

<script language="javascript" type="text/javascript"> 
    $(document).ready(function() { 
    $('#RadioDiv input').click(function() { 
    $("#info").text('Selected Value: ' + $("#RadioDiv input:radio:checked").val()); 
     if ($("#RadioDiv input:radio:checked").val() == 0) { 
       document.getElementById('Restaurent').style.display = "none"; 
       } 
       else { 
       document.getElementById('Restaurent').style.display = ""; 
        } 
     }); 
    }); 
</script> 

下面的HTML代码

<div id="RadioDiv"> 
<asp:RadioButtonList ID="ckbRestaurent" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" > 
    <asp:ListItem selected="true" Value="0">No</asp:ListItem> 
    <asp:ListItem Value="1">Yes</asp:ListItem> 
</asp:RadioButtonList> 
</div> 
<table class="style1"> 
     <tr> 
     <td ></td><td></td> 
     </tr> 
     <tr><td ></td><td></td> 
     </tr> 
</table> 
    </br> 
<div id="Restaurent" style="display:none" > 
<!-- Details Group Restaurent Table --> 
<table cellpadding="0" cellspacing="0" class="tableDetailsGroupOne"> 
    <tr> 
     <td class="tableDetailsGroupOneLabel">Restaurant One:</td> 
     <td> 
     <asp:TextBox ID="txtRestaurentOne" runat="server" CssClass="txtNameOfHotel">Restaurent One</asp:TextBox> 
     </td> 
</tr> 
<tr> 
     <td class="tableDetailsGroupOneLabel">Restaurent Two:</td> 
     <td> 
<asp:TextBox ID="txtRestaurentTwo" runat="server" CssClass="txtNameOfHotel" ></asp:TextBox> 
     </td> 
</tr> 
</table> 
</div> 
<!-- Details Group Restaurent Table END--> 

我也很欣赏谁也回答了我的问题,因为我使用ASP.NET服务器控件想解决其他用户。

0

你需要一个客户端JavaScript调用挂钩到您的单选按钮列表的YES选项。在javascript函数,你可以这样做$( “#XYZ”)。隐藏()或$( “#XYZ”)。节目()

0

试试这个代码

$(document).ready(function(){ 
     $("#xyz").hide(); 
     $("input[type=checkbox]").click(function(){ 
      if ($(this).attr('checked')){ 
       $("#xyz").show(); 
      } 
      else { 
       $("#xyz").hide(); 
      } 
     }); 

    }); 

和PLE添加HTML代码,以便我们可以通过修改上面的脚本

+0

脚本你给我只能隐藏DIV“XYZ”上的Page_Load,我是新来的jQuery,我无法找到凡在你的代码要检查,如果检查框的值是0或1,应该因此如果值是1,那么它应该显示DIV,否则隐藏DIV。感谢您的回复。 – Student

+0

你可以让我看看你的HTML代码,这样我可以帮助你 – run

+0

我已经添加代码到您的回复.. – Student

0

我加入HTML版本,你所提到的。试着理解并让我知道。

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function(){ 
     $("#xyz").hide(); 
     $("input[type=checkbox]").click(function(){    
      if ($(this).val()=='0' && $(this).attr('checked')){ 
       $("#xyz").show(); 
      } 
      else { 
       $("#xyz").hide(); 
      } 
     }); 

    }); 
</script> 
</head> 
<body> 
<input type="checkbox" value="0">yes 
<input type="checkbox" value="1">no 
<div id="xyz"> something.. </div> 
</body> 
</html> 
+1

和遗憾,更何况我不是一个人.det。我可以帮你用jQuery和HTML。 – run

+0

这不会帮助,我必须严格坚持的 Student

+0

没问题,我仍然感谢您的帮帮我。谢谢 – Student