我使用的是最新版本的 Select2。想要在下拉列表的末尾添加一个插入新按钮。我尝试了网上找到的这两种解决方案
解决方案1:
$(".select2-drop").append('<table width="100%"><tr><td class="row"><button class="btn btn-block btn-default btn-xs" onClick="modal()">Add new Item</button></div></td></tr></table>');
Run Code Online (Sandbox Code Playgroud)
解决方案2
$("#itemId0").select2("container").find("div.select2-drop").append('<table width="100%"><tr><td class="row"><button class="btn btn-block btn-default btn-xs" onClick="modal()">Add new Item</button></div></td></tr></table>');
Run Code Online (Sandbox Code Playgroud)
使用解决方案 1 没有任何反应。使用解决方案 2 我在选择 2 js 文件中收到错误消息
0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“应用”
有人可以帮忙吗?
这是我的 HTML
<select id='itemId0' name='product[0][name]' class='form-control col-lg-5 itemSearch' >
<option></option>
</select>
Run Code Online (Sandbox Code Playgroud)
和完整的 select2 javascript
function productFormatResult(product) {
if (product.loading) product.text;
var html = "<table><tr>";
html += "<td>";
html += product.text;
html += "</td></tr></table>";
return html;
}
// alert(html);
function productFormatSelection(product) {
var selected …Run Code Online (Sandbox Code Playgroud)