select2的相关问题

摘要:
select2不能在弹出框中使用的问题:通常,您只需在加载相关js和css后添加以下代码即可使用select2:$(“#selectId”)select2();但是,如果选择在弹出框中,则以这种方式使用它通常是无效的。此时,您需要写:$。fn。单元构造函数。原型inforceFocus=函数(){$(“#selectId”).select

在弹出框中无法使用select2的问题:

通常情况下,使用select2只需要在加载相关js和css后,添加如下代码即可:

$("#selectId").select2();

但如果这个select在弹出框中,这样使用往往是无效的,这时候需要这样写:

$.fn.modal.Constructor.prototype.enforceFocus = function () {$("#selectId").select2(); };

参考https://github.com/select2/select2/issues/1436

select2设置默认选中:

设置value为pxx的项选中 

$('#area').val(pxx).trigger("change");

 设置text为pxx的项选中 

$("#area").find("option[text='pxx']").attr("selected",true).trigger("change");

上面代码无效,要使用下面代码

$("#area option").filter(function(){return $(this).text()=='pxx';}).prop("selected",true).trigger("change");

(使用默认select不需要.trigger("change"))

多个select2示例化,并且某个select2需要ajax获取数据时,需将ajax获取数据的select2放到最后实例化,否则无效

$('.select2').select2();
$('.select2_required').select2({allowClear:false});
$('#create_by').select2({}, "{:url('ajaxGetUserList')}");

免责声明:文章转载自《select2的相关问题》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ubuntu16安装与配置win10系统matlab64位环境下安装libsvm工具箱下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

解决select2在bootstrap的modal中默认不显示的问题

转https://www.cnblogs.com/skybreak/p/6137035.html 在Bootstrap中的Modal,select2插件会有不显示,因为其z-index小于modal,还有另外一个问题是,修正z-index之后,select2不会自动失去焦点的问题。代码解决如下: <style> /*select2在Bo...

AngularJS+Select2实现多选框

AngularJS+Select2实现多选框 Select2是一款下拉框美化插件chosen的扩展,它能让丑陋的、很长的select选择框变的更好看、更方便,支持搜索,远程数据集,以及无限滚动的结果。 效果预览 有了select2,你就可以实现这样的下拉框 引入资源 和所有和js插件一样,select2也需要引入一些资源。这里提供一份在线版的和一份本地版...

layui下拉多选formSelects使用方法

下载formSelects-v4插件(引入formSelects-v4.css和formSelects-v4.js) 下载地址:https://fly.layui.com/extend/formSelects/#download <link rel="stylesheet" href="http://t.zoukankan.com/style/fo...

select2搜索框查询加遍历

<div class="form-group"> <label class="control-label col-sm-1 no-padding-right" for="entId">公司名称</label> <div class="...

select2动态查询及多选

引入select2.min.js和select2.css <link rel="styleSheet" href="http://t.zoukankan.com/plugin/select2/css/select2.css" type="text/css"> <script src="http://t.zoukankan.com/plug...