【发布时间】:2019-12-30 07:29:23
【问题描述】:
我有一个 html 表格,我想使用切换来显示其他信息(然后向下推其他行)。
描述我想做什么的图片:https://www.screencast.com/t/SBzG2IN9 单击切换时,显示附加行(绿色)并将表格向下推。
注意:下面的代码不是 HTML,而是 WordPress 工具集的后端。 [wpv-post-id] 是一个工具集变量,它将在前端输出 wordpress postid。例如,1915,因此 data-prod-cat="1915" 并且类变为“cat1915”。
[wpv-post-excerpt format="noautop"] 还以纯文本形式输出相应的帖子摘录(不带
)。
更新: 我更新了代码,并且切换按钮 设法将显示 从 display:none 更改为 display: table-row;但是,摘录中没有显示新行。
更新 2:已解决!
这是循环输出:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<table width="100%">
<thead>
<tr>
<th>[wpv-heading name="types-field-release-date"]Year[/wpv-heading]</th>
<th>[wpv-heading name="post-link"]Title[/wpv-heading]</th>
<th>[wpv-heading name="types-field-publisher"]Publisher[/wpv-heading]</th>
<th>[wpv-heading name="post-excerpt"]Synopsis[/wpv-heading]</th>
</tr>
</thead>
<tbody class="wpv-loop js-wpv-loop">
<wpv-loop>
<tr>
<td>[types field='release-date' style='text' format='Y'][/types]</td>
<td>[wpv-post-link]</td>
<td>[types field="publisher"][/types]</td>
<td><a href="#" class="toggler" data-prod-cat='[wpv-post-id]'><i class="fa fa-caret-square-o-down" aria-hidden="true"></i></a></td>
</tr>
<tr class="cat[wpv-post-id]" style="display:none" [wpv-post-excerpt format="noautop"]></tr>
</wpv-loop>
</tbody>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
jQuery(document).ready(function(){
jQuery(".toggler").click(function(e){
e.preventDefault();
jQuery('.cat'+jQuery(this).attr('data-prod-cat')).toggle();
});
});
【问题讨论】:
-
你能把这段代码放在sn-p里吗?
-
谢谢@RevtiShah。我只是将页面中的源代码复制到该链接中。不完全确定我是否正确。我在那里添加了 html+JS:codepen.io/beans9/pen/WRveKO
-
你找到解决办法了吗?
-
嗨@RevtiShah,很遗憾,还没有。