【问题标题】:How to set value in input tag after clear() using selectize js如何使用selectize js在clear()之后在输入标签中设置值
【发布时间】:2021-06-14 09:37:46
【问题描述】:

早上好,我是 selectize.js 的新手,我想在使用 selectize.js 的清除功能后在输入标签中设置值,这是我的代码

$('#selectize-update-endUser').selectize()[0].selectize.clear()
const endUsers = "america, japan";
$('#selectize-update-endUser').val(endUsers);
$('#selectize-update-endUser').selectize({
  plugins: ['remove_button'],
  delimiter: ',',
  persist: false,
  create: true,
});

请帮帮我,谢谢

【问题讨论】:

    标签: javascript input selectize.js


    【解决方案1】:

    我已经解决了问题 这是代码

    //set the value to a constant variable and use split function to make the two string separated by comma will become array
     const endUsers = "america, japan".split(',');
    
    //intialize the input tag into selectized        
    $('#selectize-update-endUser').selectize({
                plugins: ['remove_button'],
                delimiter: ',',
                persist: false,
                create: true,
            });
    
      //clear the input that selectized      
      $('#selectize-update-endUser').selectize()[0].selectize.clear()
    
         //set the value into the input tag that selectized Note: use for loop if the value given is separated in delimeter 
       for (const user of endUsers) {
                $('#selectize-update-endUser').selectize()[0].selectize.createItem(user);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      • 2022-01-14
      • 2017-09-25
      • 2017-12-24
      • 2018-07-29
      相关资源
      最近更新 更多