从数据库插入选择框列

时间:2018-10-13 11:58:42

标签: php mysql laravel

从数据库中检索表。没问题。但是该表的两列,我想用选择框检索它们。

我尝试过这样。但是仍然看到两个分开的列。 在这里:

我的专栏:https://imgur.com/a/nR5ML7w

我的观点:https://imgur.com/a/9VOmkOB

还jquery:https://imgur.com/a/Wq6hNLC

2 个答案:

答案 0 :(得分:1)

您必须将两列添加到视图中,并使用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>

答案 1 :(得分:0)

  • 从数据库中检索所有列,并在视图中进行编码以 显示所有列
  • 使用JQuery在标题中设置下拉值,并在页面加载时隐藏相关列
  • 制作一个JQuery函数以显示/隐藏下拉菜单中选择的表的列

让我知道您是否了解或需要示例代码。

相关问题