插件: bootstrap-select2 下拉列表的使用学习笔记

版权声明: https://blog.csdn.net/zgpeterliu/article/details/79964105

https://www.cnblogs.com/landeanfen/p/5099332.html

https://github.com/select2/

https://select2.org/


1)引用css和js

<linkhref="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css"rel="stylesheet" />

<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>


2)使用

<selectclass="js-example-basic-single" name="state">

<optionvalue="AL">Alabama</option>

...

<optionvalue="WY">Wyoming</option>

</select>


// In your Javascript (external .js resource or <script> tag)

$(document).ready(function(){

$('.js-example-basic-single').select2();

});


3)设置值:

Selecting options

To programmatically select an option/item for a Select2 control, use the jQuery .val() method:

$('#mySelect2').val('1'); // Select the option with a value of '1'
$('#mySelect2').trigger('change'); // Notify any JS components that the value changed


1、获取选中的值
var oMenuIcon = $("#txt_menuicon_web").select2({ placeholder: "请选择菜单图标", templateResult: oInit.formatState, templateSelection: oInit.formatState });
oMenuIcon.val();
2、设置select2的选中值
var oMenuIcon = $("#txt_menuicon_web").select2({ placeholder: "请选择菜单图标", templateResult: oInit.formatState, templateSelection: oInit.formatState });
oMenuIcon.val("CA").trigger("change");

阅读更多

没有更多推荐了,返回首页