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 ');}});