Select is a pitfall

Source: Internet
Author: User

Select is a pitfall
I. pitfalls encountered by select 1. default value for select assignment-multiple choice and single choice 1.1 single choice: $ ('# id '). val (value); // here is the string 1.2 Multiple options: $ ('# id '). val (array); // here you must convert a string (or other non-array) consisting of multiple values into an array 1.2.1 string to an array: str. split (",");//Change OriginalString, no new array is created, so the original string is changed to an array,OnlyStr. split (","); you can convert the 1.2.2 array to a string: array. join (","); // create a new string,Will not change the originalSo if you need to modify the original array as a string,Array = array. join (",");1.2.3 Similarly, the splice () method changes the original data. The slice method creates new data without changing the original data.
2. select does not have a specific option, but you need to set this value to the default value (business needs) 2.1 conceptual understanding: select assignment (or default value) is created when the option exists (value in option). If no option exists, the value cannot be assigned 2.2 and the option is set to disabled. However, at this time, the disabled data cannot be obtained in the background --- you can change the data originally disabled to editable '$ ('. disabled '). attr ("disabled", true) --> $ ('. disabled '). attr ("disabled", false) "2.3 sets the option display: hidden; // invalid !!! 3. When using the select2 plug-in, you need to set the mutex option in the select box (for example, when you select all, only all other options are cleared. If you select other options, none of them are available, mutual Exclusion. Or select the post option (The item selected later replaces the current option))

$ ('# Areaitem '). on ('change', function () {// select change event var _ this = $ (this); var codes = _ this. val (); if (codes [0] = '0') {// 0 indicates all _ this. val (0); _ this. trigger ('change. select2 ');}});

 

 

 

 

 

 

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.