【发布时间】:2013-06-06 20:12:29
【问题描述】:
我有一个 2 行表 - 第一行是单列,第二行是 3 列。
4 个“表格单元格”中的每一个都有一个图形和一个标题,并被分配了相同的类
我希望能够单击 4 个单元格中的任何一个,隐藏所有 4 个单元格的内容,并根据单击的单元格将它们替换为新内容。
我可以让它工作(使用 show 和 hide 方法)都在第二个表格行中的 3 个单元格,通过为每个单元格分配相同的 td 类,但不知道如何制作单个顶行单元格可单击以隐藏底部 3 个单元格,或单击底部 3 个单元格中的任何一个并隐藏顶行单元格以及第二行中的其他 2 个单元格。
有没有简单的方法用 jQuery 做到这一点?
使用代码更新
很抱歉没有发布代码。在这方面我是全新的,到目前为止才知道,但现在明白你为什么想看它了...:-)
这是我目前所拥有的。提前感谢您的帮助。
$(document).ready(function () {
$('.box').hide().filter('.top').show();
$('.box h1').click(function () {
$(this).hide();
$(this).parent().siblings().hide();
$(this).siblings().show().last();
$(this).siblings('a.up-link').click(function () {
$(this).siblings().hide().filter('h1').show();
$(this).parent().siblings(':not(h1)').show();
$(this).remove();
});
});
});
<table width="100%" border="0" cellpadding="0">
<tr>
<td class="box top">
<h1 style="background-image:url(blue.jpg);width:275px;height:230px; background-repeat:no-repeat;">
<p class="caption-2">
Topic 1
</p>
</h1>
<div class="box">
<h1>Answer 1</h1>
</div>
</td>
</tr>
<tr>
<td class="box top">
<h1 style="background-image:url(blue.jpg);width:275px;height:230px; background-repeat:no-repeat;">
<p class="caption-2">
Topic 2
</p>
</h1>
<div class="box">
<h1>Answer 2</h1>
</div>
</td>
<td class="box top">
<h1 style="background-image:url(blue.jpg);width:275px;height:230px; background- repeat:no-repeat;">
<p class="caption-2">
Topic 3
</p>
</h1>
<div class="box">
<h1>Answer 3</h1>
</div>
</td>
<td class="box top">
<h1 style="background-image:url(blue.jpg);width:275px;height:230px; background- repeat:no-repeat;">
<p class="caption-2">
Topic 4
</p>
</h1>
<div class="box">
<h1>Answer 4</h1>
</div>
</td>
</tr>
</table>
【问题讨论】:
-
你的 HTML 是什么? 展示我们总是比描述我们更好。
-
你必须向我们展示你尝试了什么
-
听起来您已经在代码上取得了一些进展,不要犹豫,发布它,我们都乐于提供帮助!
-
小伙伴们,等他更新代码吧,别贸然投票给他!!
-
@DontVoteMeDown 感谢您对新手的支持...:-)
标签: jquery