【问题标题】:How would i add a drop down menu to my jquery table which uses mysql?我如何向使用 mysql 的 jquery 表添加下拉菜单?
【发布时间】:2017-07-02 20:13:39
【问题描述】:

所以目前我正试图弄清楚如何将下拉菜单添加到我在下面发布的代码中。我已经搜索了互联网,但找不到适合我的方法,我对编码很陌生,所以这对我来说有点困难,其他人可能会觉得这很容易。

<table class="table table-bordered table-striped">
  <thead> <!-- add class="thead-inverse" for a dark header -->
    <tr>
        <th>ID</th>
        <th>USERNAME</th>
        <th>Crime(s)</th>
        <th>Active</th>
        <th>EDIT</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
    </tr>
        </div>
      </th>
  </tfoot>';
  if(mysqli_num_rows($result) > 0)
  {
      while($row = mysqli_fetch_array($result))
      {
           $output .= '  
                <tr>  
                     <td>'.$row["id"].'</td>  
                     <td class="username" data-id1="'.$row["id"].'" contenteditable>'.$row["name"].'</td>  
                     <td class="crime" data-id2="'.$row["id"].'" contenteditable>'.$row["crime"].'</td>  
                     <td class="activated" data-id2="'.$row["id"].'" contenteditable>'.$row["activated"].'</td>  
                     <td><button type="button" name="delete_btn" data-id3="'.$row["id"].'" class="btn btn-xs btn-danger btn_delete">DELETE</button></td>  
                </tr>  
           ';
      }
      $output .= '  
         <tr>  
              <td></td>  
              <td id="name" contenteditable></td>  
              <td id="crime" contenteditable></td> 
              <td id="activated" contenteditable></td>  
              <td><button type="button" name="btn_add" id="btn_add" class="btn btn-xs btn-success">ADD ACCOUNT</button></td>  
           </tr>  
      ';
   }
   else
   {
      $output .= '<tr>  
                          <td colspan="4">Data not Found</td>  
                  </tr>';
   }
   $output .= '</table>  
      </div>';
   echo $output;
 ?> 

【问题讨论】:

  • 为了清楚起见,我想在您单击活动下的框时添加一个下拉菜单,该框将有几个选项,单击后会出现一个下拉菜单,然后您选择一个选项,然后更改和更新.
  • 您要在哪里添加下拉菜单?它应该包含什么值@bluqe-bluqe
  • @AceKYD 我正在尝试将下拉菜单添加到已激活的部分。它将包含是、否和正在验证。

标签: php jquery html css mysql


【解决方案1】:

由于您提到要将下拉列表添加到表的已激活部分,并且它应该包含 YesNoBeing Verified,因此您可以将该表列更新为

<td class="activated" data-id2="'.$row["id"].'" contenteditable>
        <select name="activated" id="activated">
            <option value="Yes" '.(($row["activated"] == "Yes") ? 'selected="selected"':"").'>Yes</option>
            <option value="No" '.(($row["activated"] == "No") ? 'selected="selected"':"").'>No</option>
            <option value="Being Verified" '.(($row["activated"] == "Being Verified") ? 'selected="selected"':"").'>Being Verified</option>
        </select>
    </td>

这将允许在下拉列表中自动选择来自 db $row["activated"] 的值。

【讨论】:

  • 谢谢你的工作!我只是在为按钮设置 CSS 样式而苦苦挣扎?
  • @BluqeBluqe 很高兴它对您有用,不要忘记将其标记为答案。您可以向&lt;select&gt; 添加一个类,然后为下拉列表添加您的css。祝你好运
  • 非常感谢您的帮助!
  • 很高兴帮助@BluqeBluqe,表示感谢的好方法是将其标记为答案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-25
相关资源
最近更新 更多