【发布时间】:2023-03-03 18:48:01
【问题描述】:
我有一张如下表:
| A header | Another header |
|---|---|
| First (some-text-initially-hidden) click | row |
在“点击”时变成了
| A header | Another header |
|---|---|
| First (some-text-should-be visible now) click | row |
在“单击”时,“单击”后未显示文本“最初隐藏的某些文本”,我想在“单击”时显示和隐藏文本 我有一个工作表,如下所示:jsfiddle
代码: HTML:
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table style="font-size: 13px;">
<th> header1</th>
<th> header2 </th>
<tbody>
<tr class="test">
<td>data-always-visible
<span class="complete">some-data-to hide and show</span>
<br>
<i class="fa fa-chevron-down" style="font-size: 9px;">Click for more details of </i>
</td>
<td> some data...</td>
</tr>
</tbody>
</table>
CSS:
.test~ .test2{
display: none;
}
.open .test~ .test2{
display: table-row;
}
.test {
cursor: pointer;
}
.complete{
display:none;
}
JS/JQuery:
$('table').on('click', 'tr.test .fa-chevron-down', function() {
$(this).closest('tbody').toggleClass('open');
$(this).closest('complete').show();
});
提前谢谢你。
【问题讨论】:
-
您是想让
.test2仅在点击后出现,还是希望它始终可见?
标签: javascript html jquery css html-table