【发布时间】:2020-08-02 12:57:30
【问题描述】:
我有如下行的 html 表:
<table id="tb" class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th>title</th>
<th>price</th>
<th>discount</th>
<th>image</th>
</tr>
</thead>
<tbody>
<tr>
<td>PRODUCT 1</td>
<td align="right">24.43</td>
<td align="right">53</td>
<td>https://images-na.ssl-images-amazon.com/images/I/81xV%2BD1OkGL._AC_SL1500_.jpg</td>
</tr>
<tr>
<td>PRODUCT 2</td>
<td align="right">50.27</td>
<td align="right">70</td>
<td>https://images-na.ssl-images-amazon.com/images/I/61d-BO4sARL._AC_SL1500_.jpg</td>
</tr>
<!-- ... many other rows -->
<!-- I added this script to put the image link inside src -->
<script>
$('#tb td:nth-child(4n)').each((i, el) => {
$(el).wrapInner(`<img src="${el.innerText}" class="img-fluid"/>`);
});
</script>
我想将每一行转换为引导卡 我尝试使用 jquery 为每个引导类 class="card" 提供:
$('#tb tr').addClass("card")
它不起作用,将每一行都返回到彼此的顶部
【问题讨论】:
-
你能添加想要的输出吗?
-
我添加了所需的输出
-
这感觉像是XY Problem 你能解释一下为什么不能修改正在渲染的模板吗?
-
@JohnPavek WordPress 管理员就是一个例子。或任何其他可以添加 CSS/JS 但不能更改模板的平台。另一个例子是 Shopify。有很多用例。
标签: javascript html jquery twitter-bootstrap