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

Experience using jquery select2 (recommended)

高洛峰
Release: 2017-01-03 16:24:29
Original
2017 people have browsed it

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

html:

<script src="/statics/matrix-admin/js/jquery.min.js"></script>
<script src="/statics/matrix-admin/js/select2.min.js"></script>
 
 
<select id=&#39;mySelect&#39;></select>
Copy after login

js:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template