我試圖在單擊按鈕時隱藏/顯示/切換div。我使用ASP.NET,一切都在ASP:Datalist中。在按鈕上顯示/隱藏某些div,並帶有JQuery按鈕單擊
我可以正確顯示或隱藏div。然而,它會打開所有的div,而不是隻選擇按鈕的那個div。該div正試圖顯示/隱藏是。內容
如何才能打開該按鈕所屬的div?
的jsfiddle - 這裏的問題的一個例子http://jsfiddle.net/kMEre/
腳本:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".content").hide();
});
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#man').live('click', function (event) {
jQuery('.content').toggle('show');
});
});
</script>
DataList控件(ASP.NET)
<asp:DataList runat="server" id="dgQuestionnaire" DataKeyField="QuestionID" >
<ItemTemplate>
<div class="question_box">
<p class="small_bold">Question <asp:Label ID="lblOrder" runat="server" Text='<%# Container.ItemIndex + 1 %>'></asp:Label></p>
<div class="Questions">
<div class="heading">
<asp:HiddenField ID="hiddenQuestionID" runat="server" Value='<%# Eval("QuestionID") %>' />
<asp:TextBox runat="server" ID="tbQuestionName" Text='<%# Eval("QuestionText") %>' CssClass="form" Width="300px"></asp:TextBox>
<input type='button' id='man' value='hide/show'>
</div> <!-- end heading -->
<div class="content">
<p class="small_bold new">Question Type</p>
<asp:DropDownList runat="server" ID="QuestnType" CssClass="question_dropdown">
<asp:ListItem Value="1">Check Boxes (Multiple Choice)</asp:ListItem>
<asp:ListItem Value="2">Drop Down</asp:ListItem>
<asp:ListItem Value="3">Open Ended</asp:ListItem>
<asp:ListItem Value="4">Radio Buttons (Single Choice)</asp:ListItem>
<asp:ListItem Value="5">Range (Percentage)</asp:ListItem>
</asp:DropDownList>
<asp:DataList ID="nestedDataList" runat="server">
<ItemTemplate>
<p class="new">Answer <asp:Label ID="lblAnswerOrder" runat="server" Text='<%# Container.ItemIndex + 1 %>'></asp:Label></p>
<asp:HiddenField ID="hiddenAnswerID" runat="server" Value='<%# Eval("AnswerID") %>' />
<asp:TextBox ID="TextBox1" runat="server" CssClass="form" Text='<%# Eval("AnswerID") %>' Width="300px"></asp:TextBox>
<asp:TextBox ID="tbAnswerText" runat="server" CssClass="form" Text='<%# Eval("AnswerTitle") %>' Width="300px"></asp:TextBox>
</ItemTemplate>
</asp:DataList>
<asp:Button runat="server" ID="updateName" CssClass="button_update" style="border: 0px;" onClick="UpdateQuestionName_Click" />
<asp:Button runat="server" ID="btnDelete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this question?');" />
</div>
</div> <!-- end Questions -->
</div> <!-- end questionbox -->
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".content").hide();
});
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#man').live('click', function (event) {
jQuery('.content').toggle('show');
});
});
</script>
</ItemTemplate>
一個id屬性值只能在頁面上使用一次。 – Daxcode 2012-03-25 17:52:08