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

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

零下一度
Release: 2017-06-26 09:25:38
Original
5493 people have browsed it

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

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

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

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

正题:

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

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

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

这个是每当下拉框值有变化的时候
$(".demo").on("change",function(e){
    // e 的话就是一个对象 然后需要什么就 “e.参数” 形式 进行获取
Copy after login
<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>
Copy after login
获取select2选中的的值
$(".demo").on("select2:select",function(e){

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

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!

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