Select2 Value Assignment

Source: Internet
Author: User

The Project Center introduced the Select2 plugin. Advantages: Can be multiple selection, search, disadvantage: Access value is not as convenient as SELECT.

Select2 Value:


Take Textvar strtext = $ (' #select2 '). Select2 (' data '). Text;
Take value
var str2value= $ ("#Select2"). Select2 ("Val");
Multi-Select
$ (' #select2 '). Select2 ({ // allowclear: true,// data:[{id:0,text: ' Hello '}, {id:1,text: ' World '}] // }); </script>
<select id= "Select2" > </select>

SELECT2 upgrade, support multi-Select, with Select2 (' data ') is an array, not a JSON,
Because of the need for Select2 (' data ') [0].text can get the corresponding value, multiple words are recycled

Select2 Assignment Value:

page with razor                    <div class= "Form-group" >                        <label class= "Control-label" >                            sales Staff:                        </ Label>                        { @id = "Salesman", @class = "Select2", @style = "width:67%;} )                        <span class= "Help-line" > @Html. validationmessagefor (M = m.salesman) </span>                    </ Div>js: <script type= "Text/javascript" >//Example: Assigning a select2 tag to a valueof            @Html. Raw ("$ (' #SalesMan '). val ("All")             $ ("#SalesMan"). Select2 ();        });    </script>

Select2 Value Assignment

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.