Create an array to obtain multiple
Val () returns the value.
<! Doctype HTML>
<HTML>
<Head>
<Meta charset = "UTF-8">
<Title> </title>
<SCRIPT src = "https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</SCRIPT>
<SCRIPT>
$ (Document). Ready (function (){
VaR DATA = new array ("0", "1", "2", "3 ");
$ ("# Tar"). Val (data );
})
</SCRIPT>
<LINK rel = "stylesheet" type = "text/CSS" href = "layui/CSS/layui.css"/>
<Style> body {padding: 20px;}. multi DL dd. layui-This {background-color: # fff} </style>
</Head>
<Body>
<Form class = "layui-form-pane" Action = "">
<Div class = "layui-form-item">
<Label class = "layui-form-label"> multiple options </label>
<Div class = "layui-input-block">
<Select multiple = "multiple" Lay-filter = "test" id = "tar">
<Option value = ""> </option>
<Option value = "0"> A </option>
<Option value = "1"> B </option>
<Option value = "2"> C </option>
<Option value = "3"> d </option>
</SELECT>
</Div>
</Div>
<Button type = "button" class = "layui-BTN-normal" id = "get-Val"> obtain the selected value </button>
</Form>
<SCRIPT type = "text/JavaScript" src = "layui/layui. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Layui. config ({
Base: 'js /',
})
Layui. Use (['elelect '], function (){
VaR $ = layui. jquery, form = layui. Form, multiselect = layui. multiselect;
$ ('# Get-Val'). Click (function (){
VaR Vals = [],
Texts = [];
$ ('Select [multiple] Option: selected'). Each (function (){
Vals. Push ($ (this). Val ());
// The push () method can add one or more elements to the end of the array and return a new length.
Texts. Push ($ (this). Text ());
})
Console. dir (Vals );
Console. dir (texts );
})
Form. On ('select (TEST) ', function (data ){
Console. dir (data );
}) // Convert the value into text and output it on the console
});
</SCRIPT>
</Body>
</Html>
Select multiple values. The default value is selected.