How to achieve autocomplete feature over HTML drop-down or select element?

后端 未结 5 876
悲&欢浪女
悲&欢浪女 2021-01-17 04:51

Hi I am trying to create auto completion functionality for a drop-down OR select html form element.

I need a functionality like once us

5条回答
  •  臣服心动
    2021-01-17 05:43

    There are many options, I have used Selectize.js and Select2. I found Select2 is much better and easy to use, and light weight! Also very easy to update with ajax call (example: search city, country, user etc...)

    link: http://selectize.github.io/selectize.js/

    checkout the example below:

    $(function() {
      $('select')
        .select2({
          placeholder: 'type now...',
          width: '200',
          multiple: true,
          data: [{
            id: 'A & A, LLC.',
            text: 'A & A, LLC.'
          }, {
            id: 'testing1',
            text: 'testing1'
          }, {
            id: 'testing 1,2,3',
            text: 'testing 1,2,3'
          }],
          tokenSeparators: ['|']
        })
        .on('change', function() {
          console.log($(this).val());
        });
    });
    
    
    
    
    
    
    

提交回复
热议问题