从数据库中检索表。没问题。但是该表的两列,我想用选择框检索那些。
我尝试过这样的。但仍然看到两个分开的列。 这是:
我的专栏:https://imgur.com/a/nR5ML7w
我的看法:https://imgur.com/a/9VOmkOB
还有 jquery: https://imgur.com/a/Wq6hNLC
最佳答案
您必须将两列添加到 View 中并使用 js 切换它们,否则您每次都必须通过 ajax 获取整个内容。这是一个 jQuery 解决方案。
$(function() {
$('.pricetag').on('change', function() {
// Sync select values on toggle
$('.pricetag').val($(this).val())
// Swap hidden columns
$('tr td:nth-of-type(2), tr td:nth-of-type(3), th:nth-of-type(2), th:nth-of-type(3)').toggleClass('price-hidden')
})
});
.price-hidden {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<thead>
<th>Name</th>
<th>
<select name="price" class="pricetag">
<option value="price">price</option>
<option value="old">old price</option>
</select>
</th>
<th class="price-hidden">
<select name="price" class="pricetag">
<option value="price">price</option>
<option value="old">old price</option>
</select>
</th>
</thead>
<tbody>
<tr>
<td>Name 1</td>
<td class="price-hidden">Old price</td>
<td>New price</td>
</tr>
<tr>
<td>Name 1</td>
<td class="price-hidden">Old price</td>
<td>New price</td>
</tr>
</tbody>
</table>
关于php - 从数据库插入选择框列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52792691/