
Select2.js 是JQuery 一個套件, 既整合了dropdown 亦加入了AutoComplete 的功能. 然而若根據文件去使用時, onChange() 卻有機會令瀏覽器不能運作.Google 了後發現是Select2.js Render 時出現問題, 但在現在(11-Apr-2018), 問題仍未解決, 那唯有利用work-around 處理.
方法就是自行於select 中加入option, 方法如下:
$("#dropDown").select2(); $.getJSON( "<<Test URL>>", function( data ) { $.each(data, function(i , d){ $('#dropDown').append('<option value="' + d.code + '">' + d.name + '</option>'); }); });
參考資料
- Select2,
https://select2.org/
Leave a Reply