首页 > 解决方案 > 下拉菜单在 jquery 数据表移动视图中不起作用

问题描述

转到小提琴 https://jsfiddle.net/rizwanali98601/ngofhc24/12/ 在下表中,jquery 数据表中有下拉菜单。

单击按钮时,我在下拉列表中添加选项。但在移动视图选项中未添加到下拉列表中。

 <p>Click on Add option  button to add options in dropdown</p>
<button type="button" id="btn1">
Add option 

</button>
<br/>

<table class="table table-striped table-hover" id="myTable">
<thead>
<tr>
  <th>Indent No.</th>
  <th>Warehouse</th>
  <th>Item</th>
  <th>Make/Catno</th>
  <th>UOM</th>
  <th>Qty</th>
  <th>Qty P</th>
  <th>Sh Cl</th>
  <th>Date</th>
  <th>SortDate</th>
  <th>Rqt Dt</th>
  <th>Dropdown</th>          
  </tr>
</thead>
<tbody>
  <tr>
    <td>INDMSF/16-17/00003</td>

    <td>Furnace</td>
    <td>Bearing 22317 EW33J</td>
    <td></td>    
    <td>no</td>
    <td>2.0</td>  
    <td>2.0</td>
    <td></td>
    <td>31/08/16</td>
    <td>08/31/16</td>    
    <td>31/08/16</td>
     <td><select id="ddlTest" style="width: 300px"></select></td>
  </tr>
 </tbody>
</table>

标签: javascriptjquerydatatables

解决方案


尝试使用.on()

所以换...

$("#btn1").click(function(){
    var ddl = $('#ddlTest');
    ddl.append($("<option></option>").val('0').html('Selectvalue'));
}); 

对此...

$("#btn1").on('click', function() {
    var ddl = $('#ddlTest');
    ddl.append($("<option></option>").val('0').html('Selectvalue'));
});

推荐阅读