【问题标题】:Using jQuery to hide/show table row for posting a reply使用 jQuery 隐藏/显示表格行以发布回复
【发布时间】:2011-09-22 04:28:17
【问题描述】:

我正在构建一个公告板系统,我们可以向其发布消息,人们可以回复消息。我发布了一条新消息工作正常,对于每条新消息,我使用 AJAX 为每条消息创建一个新的表格行:

<table id="content-table">
<tr>

  <th scope="col" class="messagetime"> <? echo $time; ?> </th>
  <th scope="col" class"message body"></th>
  <th scope="col" class="messagereply"><form method="GET" action="Rindex.php"><input name="id" type="hidden" value="<? echo $id; ?>"><button type="submit" style="border-style:none;" class="post-icon" /></form></th>

</tr>
</table>

在最后一列中,我有一张他们按下的图像,我希望 jQuery 在该行下方创建一个新表格行,其中包含用于输入回复消息的字段,该回复消息将发布到该特定消息。

我目前可以为每条消息获取一个新行并隐藏/显示所有消息,但我无法弄清楚如何让回复按钮定位到唯一行来回复消息:

<table id="content-table">
<tr>

  <th scope="col" class="messagetime"> <? echo $time; ?> </th>
  <th scope="col" class"message body"></th>
  <th scope="col" class="messagereply"><form method="GET" action="Rindex.php"><input name="id" type="hidden" value="<? echo $id; ?>"><button type="submit" style="border-style:none;" class="post-icon" /></form></th>

</tr>

<tr id="replyrow" class="replyrow">

 <th scope="col"></th>
 <th scope="col" class="replyrowcontent"> <Post Reply Form would be in here.> </th>
 <th scope="col"></th>

</tr>
</table>

有什么建议吗?我有一种感觉会涉及到父母/孩子的关系,但我在脑海中概念化了这一点!

【问题讨论】:

  • 我的建议是不要使用表格进行布局。
  • 有什么建议吗?你知道这很有趣。看看 stackoverflow 如何有一个隐藏的 DIV 来显示您何时想要回复消息?我正在尝试这样的事情......

标签: jquery ajax html-table row toggle


【解决方案1】:
<div stlye="disply:none;" id="hidden">
    Hidden
</div>



<script>
$.ajax({
   /* ... other options here... */
   success: function (){
       $('#hidden').show();
   }
});
</script>

现在显然你需要进行一些研究......你也可以使用click()方法并将ajax放在那里,或者类似的东西......

糟糕,忘记给你链接了 http://api.jquery.com/jQuery.ajax/

祝你好运,如果您有更多问题,请使用 [comment] 下面的框,如果有问题我会回答您的问题

【讨论】:

  • 同时查找delay()queue(),所以如果你愿意的话,你可以在成功后给它一个延迟,这样它就不会隐藏得那么快,也许fadeOut()会更有效不仅仅是隐藏它并显示它:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-28
  • 2010-10-28
  • 1970-01-01
  • 2015-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多