对此必须有一个简单的解释。
我有一个父<div>
标记,其中包含许多子div,这些子div需要根据它们的类进行隐藏。问题是,我甚至不能获得我的父div的句柄。到底是什么问题呢?我要从我的葫芦里出来。
jQuery代码(代码片段)如下所示:
$(function() {
$('#dasummary').children().hide();
违规的<div>
部分及其所有内容如下:
<asp:ListView ID="lvLedger" runat="server" DataSourceID="ldsLedger">
<LayoutTemplate>
<h2>Current Day Activity Summary</h2>
<div id="#dasummary">
<div id="itemPlaceholder" runat="server" />
</div>
</LayoutTemplate>
<ItemTemplate>
<div id="toggleRow" runat="server" class="group">
<asp:Image ID="imgToggle" runat="server"
ImageUrl="~/App_Themes/SunDIAL/images/maximize.png"
ImageAlign="Left" />
<%# Eval("Key") %> (<%# Eval("Count") %> entries)
</div>
<!-- Add nested ListView control for individual items here -->
<asp:ListView ID="lvItems" runat="server" DataSource='<%# Eval("Tasks") %>'>
<LayoutTemplate>
<div class="activity_summary">
<table>
<thead>
<tr>
<th class="first" />
<th>Day</th>
<th>Job</th>
<th>Batch</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
<tr id="itemPlaceholder" runat="server" />
</tbody>
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr id="item" runat="server" class="itemRow">
<td class="first" />
<td>
<h4>
<a><%# Eval("Day") %></a>
</h4>
</td>
<td><%# Eval("Project") %></td>
<td><%# Eval("Name")%></td>
<td><%# Eval("Hours") %>:<%# Eval("Minutes","{0:00}") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
</ItemTemplate>
</asp:ListView>
呈现的HTML看起来(据我所知)还不错。如果您想要全部内容,请告诉我;这里是重要的部分:
<div id="#dasummary">
<div id="ctl00_ContentPlaceHolder1_dashboardFrame_ctl00_ActiveDayLedger1_lvLedger_ctrl0_toggleRow" class="group">
<img id="ctl00_ContentPlaceHolder1_dashboardFrame_ctl00_ActiveDayLedger1_lvLedger_ctrl0_imgToggle" src="App_Themes/SunDIAL/images/maximize.png" align="left" style="border-width:0px;" />
Wednesday (2 entries)
</div>
<!-- Add nested ListView control for individual items here -->
<div class="activity_summary">
我这么简单的操作失败肯定是有原因的。你能认出它吗?
发布于 2009-01-11 01:47:27
div的id是错误的。在html中,它必须是dasummary
,而不是#dasummary
,因此您可以使用$("#dasummary")
通过jQuery获取它
发布于 2009-01-11 02:11:37
jQuery选择器中的"#“表示jQuery应该根据id选择元素。因此,在您的情况下,有两种方法:
发布于 2009-01-11 02:13:17
是的,你应该
<div id="dasummary">
此外,可能还需要使用each函数:
$("div", "#dasummary").each(function() {
$(this).hide();
});
https://stackoverflow.com/questions/432658
复制相似问题