Home > Web Front-end > JS Tutorial > body text

Detailed explanation of examples of angular select2 drop-down single selection and multi-selection

零下一度
Release: 2017-06-25 09:11:57
Original
6353 people have browsed it

Compatibility:

Introduction file

/select2.min.js/select2.min.css
Copy after login

html

<select class="form-control selectName" multiple="multiple">//设置class名为selectName;配置为多选 multiple
        <option value="1" disabled="disabled">本人</option>   //设置一项option为不可选 disabled="disabled"
        <option value="2">父母</option>
        <option value="3">配偶</option>
        <option value="4">子女</option>
        <option value="5">其他</option>
        <option value="6">全部</option>
</select>
Copy after login

js

$(".custAndInsRelationRange").select2({
     placeholder: "--请选择--";     //设置select的默认显示文字});
Copy after login

Attachment:

select2 ----- Single selection value assignment

html:

<select class="form-control premPeriod" ng-model="selectModel" ng-options="item.value as item.name for item in selectDataList"></select>
Copy after login
<em><br>//ng-model="selectModel" 设置ng-model,它的值等于 item.value<br><br>//selectDataList是接口数据</em>
Copy after login
//select下拉显示的值是item.name
Copy after login

js:

$(".premPeriod").select2({ placeholder: "--请选择--"; //初始化 });
Copy after login
$scope.selectModel= '' //直接操作ng-model上的值
Copy after login

select2 --- -- Multiple selection value assignment

html:

<select class="form-control premPeriod" multiple="multiple" id="premPeriod" ng-options="item.value as item.name for item in selectDataList">
        <option value="1">5</option>
        <option value="2">10</option>
        <option value="3">15</option>
        <option value="4">20</option>
</select>
Copy after login

js:

$(".premPeriod").select2({ placeholder: "--请选择--";  });//初始化
Copy after login
$scope.selectModel= $("#premPeriod").val();//取select值

$scope.defaultData = ['2','3'];//默认值
Copy after login
$(".premPeriod").val($scope.defaultData);//设置select的默认值
Copy after login

The above is the detailed content of Detailed explanation of examples of angular select2 drop-down single selection and multi-selection. 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