我想添加一個新的按鈕來選擇2 drop甚至用戶不能得到他們的結果或不,但我追加這個按鈕後,我不能使用jquery點擊。如何在Select2中添加按鈕並在select2-no-results中調用Select2中的click事件?
$('.city').select2({
formatNoMatches: function(term) {
return "<a href='{{route('addNewIterms')}}' class='btn btn-info btn-sm' id='add'> Add New Item </a>";
}
});
Another solution
$('.select2-drop ').append("<a href='{{route('addNewIterms')}}' class='btn btn-info btn-sm' id='add'> Add New Item </a>");
但我不能把點擊事件雖然我嘗試jQuery的DOM事件像下面
$(document).on('click','.select2-drop,.select2-drop#add', function(){
console.log(this)
})
你的問題不清楚! – ZeJur
當我使用JQuery的select2和我使用JQuery的append方法都選擇formatNoMatches方法插入一個按鈕添加上select2下拉,但之後,我將使用document.onclick在此按鈕,但不工作 –
嘗試使用標點符號。否則,真的很難理解你! – ZeJur