利用引导多选实现下拉框多选功能

  

利用引导多选实现下拉框多选功能,并在点击事件中获取到所有选中选项的值值

  

首先展示项目案例:

  

利用引导多选实现下拉框多选功能

  

多选下拉框功能实现gif

  

下面是所有完整的代码,重点以及主要的解释已经在代码内进行注释:
  

  

引入的css, js文件需要从github中下载:https://github.com/davidstutz/bootstrap-multiselect
  

  

插件依赖金桥和引导,所以在引入插件之前需要先引入这金桥和引导的css和javascript文件。
  

        & lt; !DOCTYPE html>   & lt; html lang=癳n”比;      & lt; head>   & lt;元charset=皍tf - 8”比;   & lt;元name=笆哟啊蹦谌?翱矶?设备宽度,初始=1.0”比;   & lt;元http-equiv=癤-UA-Compatible”内容=癷e=边缘”比;   & lt; title>实现下拉框多选功能& lt;/title>   & lt;链接rel="样式表" href=" https://www.yisu.com/zixun/docs/css/bootstrap-3.3.2.min.css " rel=巴獠縩ofollow”type=" text/css "比;   & lt;链接rel="样式表" href=" https://www.yisu.com/zixun/docs/css/bootstrap-example.min.css " rel=巴獠縩ofollow”type=" text/css "比;   & lt;链接rel="样式表" href=" https://www.yisu.com/zixun/docs/css/prettify.min.css " rel=巴獠縩ofollow”type=" text/css "比;   & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/docs/js/jquery-2.1.3.min.js "祝辞& lt;/script>   & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/docs/js/bootstrap-3.3.2.min.js "祝辞& lt;/script>   & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/docs/js/prettify.min.js "祝辞& lt;/script>   & lt;链接rel="样式表" href=" https://www.yisu.com/zixun/dist/css/bootstrap-multiselect.css " rel=巴獠縩ofollow”type=" text/css "比;   & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/dist/js/bootstrap-multiselect.js "祝辞& lt;/script>   & lt;脚本type=" text/javascript祝辞   美元(文档)。准备好(函数(){   window.prettyPrint (),,prettyPrint ();   });//插件实例   美元(文档)。准备好(函数(){   $ (" # example-getting-started ") .multiselect ();//点击事件获取所有选值中选择的价值   $ (" # btn”)。点击(函数(){   var selectValueStr=[];   $ (" # example-getting-started选项:选择")。每个(函数(){   selectValueStr.push($(这).val ());   })   console.log (selectValueStr)   })   });   & lt;/script>   & lt;/head>      & lt; body>   & lt;按钮id=" btn "祝辞获取选中得选择中值值& lt;/button>   & lt;选择id=癳xample-getting-started”多个=岸喔觥北?   & lt;选项值=" https://www.yisu.com/zixun/cheese "祝辞Cheese   & lt;选项值=" https://www.yisu.com/zixun/tomatoes "祝辞Tomatoes   & lt;选项值=" https://www.yisu.com/zixun/Mozzarella "祝辞Mozzarella   & lt;选项值=" https://www.yisu.com/zixun/Mushrooms "祝辞Mushrooms   & lt;选项值=" https://www.yisu.com/zixun/Pepperoni "祝辞Pepperoni   & lt;选项值=" https://www.yisu.com/zixun/Onions "祝辞Onions   & lt;/select>   & lt;/body>      & lt;/html>      

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

利用引导多选实现下拉框多选功能