我需要添加“添加新项目"Select2中的选项 [英] I need to add "Add new item" option in Select2

查看:67
本文介绍了我需要添加“添加新项目"Select2中的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在列表的第一个元素中将一个按钮添加到添加新项".如果用户单击该按钮,则需要打开一个弹出窗口并从用户那里获取输入.如何在select2插件中执行此操作?(或)是否需要为此自定义任何默认选项?

I want to add a button in first element of the list to "Add new item". If user clicks on that button I need to open a pop-up and get the input from users. How to do this in select2 plugin? Is any default options for this (or) need to customize this?

推荐答案

这是我的方法

$('#select2')
    .select2()
    .on('select2:open', () => {
        $(".select2-results:not(:has(a))").append('<a href="#" style="padding: 6px;height: 20px;display: inline-table;">Create new item</a>');
})

这篇关于我需要添加“添加新项目"Select2中的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆