【发布时间】:2018-05-02 03:33:36
【问题描述】:
我想通过单击添加按钮在我的 HTML 表中动态添加一行。该行包含一个使用 selectpicker 类 的选择元素。当我在脚本中删除 selectpicker 类以添加新行时,选择元素完美地出现在新创建的行中。但是当我在脚本中使用 selectpicker 时,元素不会呈现。
这是我的桌子:
$(".addRow").click(function() {
$(this).closest('table').find('tr:last').prev().after('<tr><td> <
select name = "myselect[]"
id = "myselect"
class = "selectpicker" >
<
option > --Select Resp.Center-- < /option> <
option value = "1" > My Option 1 < /option> <
option value = "2" > My Option 2 < /option> <
option value = "3" > My Option 3 < /option> <
/select> <
/td> <
td >
<
a href = "#"
class = "removeRow" > < i class = "fa fa-minus-square fa-fw" > < /i></a >
<
/td> <
/tr>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="myTable">
<tr class="myRow">
<td>
<select name="myselect[]" id="myselect" class="selectpicker" data-live-search="true">
<option>--Select Option--</option>
<option value="1">My Option 1</option>
<option value="2">My Option 2</option>
<option value="3">My Option 3</option>
</select>
</td>
<td><a href="#" class="addRow"><i class="fa fa-plus-square"></i></a></td>
</tr>
</table>
【问题讨论】:
-
已经解决了。刚刚使 bootstrap-select.js 最后加载。
标签: javascript jquery html bootstrap-selectpicker