我有一个绑定(bind)到 GenericList 的 ListView,并且为每个 Item 创建了这个 tr 和 td 的结构:
<tr>
<td>Name</td>
<td>Surname</td>
<td>14/08/2009</td>
<td><a href="#" class="trigger">Show</a></td>
</tr>
<tr>
<td colspan="4">
<div class="showPicture">
<img src="" alt="" />
</div>
</td>
</tr>
我的问题是我想显示和隐藏包含图像的 div,而不使用回发到服务器。我想做的是获取被单击的链接,找到它的父 td 和父 tr,导航到下一个 tr 并找到其中的 div。
我想出了以下 JavaScript 来尝试获取正确的 div 并显示或隐藏它,但它给了我以下错误:“Microsoft JScript 运行时错误:'parents(...).parents(.. .).nextSibling.firstChild' 为 null 或不是对象"
<script type="text/javascript">
$(function(){
$("div.shareLink").hide();
$("a.trigger").click(function(eventObject){
$(this).parents('td').parents('tr').nextSibling.firstChild.firstChild.toggle(400);
return false;
});
});
</script>
我是 JavaScript 新手,刚刚开始在 ASP.NET 中进行开发,就像我以前开发 Windows 应用程序一样,所以如果有人能够提醒我我做错了,我将非常感激。
提前致谢, 托尼奥
最佳答案
试试这个:
$(this).parent().parent().next().find('div.showPicture').toggle();
关于c# - 在 ListView 中显示/隐藏 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1287122/