<form method="post">
    <select class="user" name="user[]" multiple></select>
</form>
$(function (){
    $(".user").select2({
        language: 'zh-TW',
        width: '100%',
        // 最多字元限制
        maximumInputLength: 10,
        // 最少字元才觸發尋找, 0 不指定
        minimumInputLength: 0,
        // 當找不到可以使用輸入的文字
        tags: true,
        data: [
            { id: 1, text: "Blue" },
            { id: 2, text: "David"},
            { id: 3, text: "Judy" },
            { id: 4, text: "Kate" },
            { id: 5, text: "John" }
        ],
    });
})

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js
  3. https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/i18n/zh-TW.js