c# - 在 ListView 中显示/隐藏 Div

标签 c# asp.net javascript listview

我有一个绑定(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/

相关文章:

javascript - 如何在 asp.net 的客户端不使用任何工具将 div 保存为 PDF?

c# - 在 IIS 服务器之间传递 Windows 身份验证

javascript - 在 where arg 中使用多个约束对查询 findAll 进行 Sequelize

C# Flag 获取组合标志的值

c# - OracleDataClientBatchingBatcherFactory 引发空引用异常

asp.net - 是否可以为 Windows Azure 网站设置 IP 限制?

javascript - 在 jQuery 中更改图像的尺寸

javascript - TableTools 未加载到 DataTables 表上

c# - 使用 Linq 在 IEnumerable<T> 中查找序列

c# - 将 List<string> 写入 Excel.Range