Home > Article > Web Front-end > What is the usage of select2 in jquery
In jquery, select2 is used to optimize select to support single and multiple selections. It also supports group display and list retrieval. It is a drop-down list plug-in based on jquery. The calling syntax is "$(select ).select2()".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
What is the usage of select2 in jquery
Select2 is a drop-down list plug-in based on JQuery, mainly used to optimize select and support single Selection and multi-selection, and also supports group display and list search.
select2 is a component used by Jquery to replace the selection box. It allows you to customize drop-down boxes and supports search, tagging, remote data sources, infinite scrolling and other more advanced features.
The download address of select2 is: https://select2.github.io/. The select2-4.0.0 version is used here. After downloading this version, unzip the file. There are js and css files in the dist directory. You need to reference these files when using select.
First introduce the css and js just downloaded into the project. Before introducing select2.js, we need to introduce jquery first.
Note that the css and js in the downloaded select2 folder have both compressed and uncompressed versions. You can import them according to your own needs. The compressed version is introduced here.
The calling syntax is as follows:
$(function () { $("#myselect").select2();//调用插件 })
Of course, we need to make some configurations for it, which are configured through objects as "$(" #myselect").select2()" Parameters of select2(), for example, we can set the width of select:
$("#myselect").select2({ width:160,//设置select标签的宽度 });
Related video tutorial recommendations: jQuery video tutorial
The above is the detailed content of What is the usage of select2 in jquery. For more information, please follow other related articles on the PHP Chinese website!