在表格中使用jQuery显示/隐藏切换 [英] Using jQuery show/hide toggle in a table

查看:90
本文介绍了在表格中使用jQuery显示/隐藏切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试改编Andy Langton的表演/隐藏/迷你手风琴( http:/ /andylangton.co.uk/jquery-show-hide )在一张桌子里工作。我想要创建一个事件列表,并在每个事件附加一个确认表单。单击最后一个单元格或行中的确认按钮后,我希望显示与此特定事件关联的表单。

I'm trying to adapt Andy Langton's show/hide/mini-accordion (http://andylangton.co.uk/jquery-show-hide) to work within a table. I'm wanting to create a list of events with a confirmation form attached to each event. Upon clicking on the 'confirm' button in the last cell or the row, I would like the form associated with this particular event to be revealed.

Andy的代码使用

$('.toggle')
    .prev()
    .append('<a href="#" class="toggleLink">'+showText+'</a>');

在隐藏表单之前动态添加切换链接(确认按钮)。但是,这会在表格行中添加链接,而不是在单元格中添加。因此我将其更改为

to dynamically add the toggle link (the confirm button) just before the hidden form. This, however, adds the link within the table row and not in a cell. I have therefore changed it to

$('.toggle')
    .prev()
    .append('<td><a href="#" class="toggleLink">'+showText+'</a></td>');

此链接现在位于正确的位置,但现在不会调用表单的显示/隐藏。当它被错误地放置时,功能有效,尽管不是很正确。我觉得调用切换操作的选择器不正确,但我不知道如何纠正它。它目前是

The link is now in the correct place but does now not invoke the show/hide of the form. When it was placed incorrectly the functionality worked, despite not being quite right. I feel that the selector calling the toggle action is not correct but I don't know how to correct it. It is currently

$(this)
    .parent()
    .next('.toggle')
    .toggle('slow');

这基本上就是源代码的样子......

This is essentially how the source looks...

<table id="training-events">
<tr>
   <th>Date / Time</th>
   <th>Event / Venue</th>
   <th>Cost</th>
   <th>Confirm</th>
</tr>
<tr class="event" valign="top">
    <td class="date">Mon, 10 August 2009<br>03:30 PM - 05:30 PM</td>
    <td><h5>Regional Director Meeting</td>
    <td>No Charge</td>
    <td><a href="#" class="toggleLink">Cancel</a></td>
</tr>
<tr style="display: none;" class="toggle">
   <td colspan="4">
      ** FORM **
   </td>
</tr>
</table>


推荐答案

你需要这样的东西:

$(this).parent().parent().next('.toggle').toggle('slow')

$(this).closest('tr').next('.toggle').toggle('slow'); 

您只需拨打一个父母()电话,将您带到TD,您需要升级到TR。

You're only making a single parent() call which brings you to the TD, you need to step up to the TR.

这篇关于在表格中使用jQuery显示/隐藏切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆