Select multiple values. The default value is selected.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.