Home  >  Article  >  Web Front-end  >  Experience using jquery select2 (recommended)

Experience using jquery select2 (recommended)

高洛峰
高洛峰Original
2017-01-03 16:24:291858browse

How to select the specified item after ajax loads the drop-down box data?

html:



 
 

js:

$(function(){
 
  $('#mySelect').select2();
 
  $.ajax({
 
    success:function(data){
 
      $('#mySelect').append();
 
      $('#mySelect').select2('val','val1');//调用select2('val','指定项value')方法选中指定项,否则无任何项被选中。如果设置的值不存在,则默认选择第一项
 
    }
 
  })
 
 
})

The above The usage experience of jquery select2 (recommended) is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.

For more jquery select2 usage experience (recommended) and related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn