2011-11-03 61 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