[英]Displaying '.hidden' elements using JQUERY
I have this asp and HTML code: 我有这个asp和HTML代码:
<asp:Repeater ID="PervousResultsList" runat="server" EnableViewState="False">
<ItemTemplate>
<div class="row1">
<table style="cursor: pointer; width: 100%">
<tr>
<td rowspan="4">
<asp:Image ID="Image1" ImageUrl="~/Images/pushpinred.png" runat="server" Width="32"
Height="32" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td rowspan="7">
<input type="button" class="toggleRow" value="B" style="height: 30px; position: relative; float: left;" />
</td>
</tr>
<tr>
<td>text:</td>
<td rowspan="4">
<h1 style="color: gray"><%# Eval("Text") %></h1>
</td>
</tr>
<tr class="hidden">
<td>text:</td>
<td><%# Eval("Text") %></td>
</tr>
<tr class="hidden">
<td>X:</td>
<td><%# Eval("Lon") %></td>
</tr>
<tr class="hidden">
<td>Y:</td>
<td><%# Eval("Lat") %></td>
</tr>
<tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
Javascript code: JavaScript代码:
$('.toggleRow').on('click', function () {
$(this).closest('table').children('.hidden').show();
return false;
});
When batten with class toggleRow clicked the javascript fired but I do not get any result (ie I expect the hidden row will be displayed but the not). 当使用类toggleRow进行板条连接时,触发了javascript,但是我没有得到任何结果(即,我希望将显示隐藏行,但不会)。
Any idea why? 知道为什么吗?
Since you have a table
and tr
, even though you are not creating tbody
the browser will put all the tr
elements in a tbody
, so your selector $(this).closest('table').children('.hidden').show();
由于您有一个
table
和tr
,即使您没有创建tbody
,浏览器也会将所有tr
元素放在tbody
,因此您的选择器$(this).closest('table').children('.hidden').show();
will not be able to find the tr
as children of the able. 将无法找到
tr
作为有能力的孩子。
So try 所以尝试
$(this).closest('table').find('tr.hidden').show();
You also will have to add the toggleRow
class to the button 您还必须将
toggleRow
类添加到按钮
<input type="button" id="btnToggleRow" value="B" style="height: 30px; position: relative; float: left;" class="toggleRow"/>
To display the row which are hidden use below code. 要显示隐藏的行,请使用以下代码。
$('.toggleRow').on('click', function () {
$('.hidden').css("display","block");
return false;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.