This is very simple to use. Other configuration items can be viewed on the official website. http://select2.github.io/options.html#core-options Today I mainly talk about the next thing"/> This is very simple to use. Other configuration items can be viewed on the official website. http://select2.github.io/options.html#core-options Today I mainly talk about the next thing">

Home  >  Article  >  Web Front-end  >  Detailed explanation of click and selected event instances of Select2 plug-in

Detailed explanation of click and selected event instances of Select2 plug-in

零下一度
零下一度Original
2017-06-26 09:25:385433browse

HTML
<input type=&#39;text&#39; class="select" />

这个就可以很简单的使用了 

其他配置项可以到官网看
http://select2.github.io/options.html#core-options
今天主要说下事件

原因
在开发中遇到最多的就是ajax加载数据之后,选中的一个时,要进行二级联动,甚至三级联动 这个就需要事件的支持了

正题:

开发中最常用的就是 选中一个时,出发一个事件   这个事件的话就jQuery 的change事件

select2的事件的话 也是可以使用这个API

<input type=&#39;text&#39; class=&#39;demo&#39; />

这个是每当下拉框值有变化的时候
$(".demo").on("change",function(e){
    // e 的话就是一个对象 然后需要什么就 “e.参数” 形式 进行获取
<em>  console.log(e);<br>})<br><br>打印出来的截图<br><br><img src="https://img.php.cn/upload/article/000/000/001/8ba02fb26ae9ecc0c51147d21e78ce6e-0.png" alt=""></em>
获取select2选中的的值
$(".demo").on("select2:select",function(e){

    // e 的话就是一个对象 然后需要什么就 “e.参数” 形式 进行获取
})
<em>这样就获取到选中的值<br><br>下面时官网提供所有的事件 给大家做个参考<br><br><img src="https://img.php.cn/upload/article/000/000/001/8ba02fb26ae9ecc0c51147d21e78ce6e-1.png" alt=""></em>

The above is the detailed content of Detailed explanation of click and selected event instances of Select2 plug-in. For more information, please follow other related articles on 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