Modify the text value according to the option's ID property
1 $ ("#sel_div. Select_class option[id= '-select Province-']"). Text (data.province). attr ("Selected", true 2 $ ("#sel_div. Select_class option[id= '-select City-']"). Text (data.city). attr (" Selected ", true ); 3 $ ("#sel_div. Select_class option[id= '-Select Zone-']"). Text (Data.area). attr (" Selected ", true ); 4 $ ("#sel_div. Select_class option[id= '-select Street-']"). Text (Data.street). attr (" Selected ", true );
Gets the text value of all option under multiple select (with the same class attribute, tangent value)
1$ ("#sel_div. Select_class option"). each (function(){//Traverse All option tags2 3 varText = $ ( This). text ();//Gets the text of option4alert (text);//The text value of the current option is displayed5 if(txt = "Select Province")6$ ("#sel_div. Select_class option[id= '-select Province-']"). Text (data.province). attr ("Selected",true);7 if(txt = "Select City")8$ ("#sel_div. Select_class option[id= '-select City-']"). Text (data.city). attr ("Selected",true);9 if(txt = = "SELECT Zone")Ten$ ("#sel_div. Select_class option[id= '-Select Zone-']"). Text (Data.area). attr ("Selected",true); One if(txt = = "Select Street") A$ ("#sel_div. Select_class option[id= '-select Street-']"). Text (Data.street). attr ("Selected",true); - -});
If there is no cascading relationship between Select, then all options are loaded and you can use the following method to display the queried data
$ ("#sel_div. Select_class option[id=" +data.province+ "]"). attr ("selected",true);
$ ("#sel_div. Select_class option[id=" +data.city+ "]"). attr ("selected",true);
$ ("#sel_div. Select_class option[id=" +data.area+ "]"). attr ("selected",true);
$ ("#sel_div. Select_class option[id=" +data.street+ "]"). attr ("selected",true);
Another way to get all option is to put all text into a string and save each character in a map
var map = $ ("#sel_div. Select_class option"). Map ( function () {
Alert ($ ( this return $ (this ). text (); }). Get (). Join ( ","
Alert (map);//Display TEXT1,TEXT2,TEXT3
Alert (map[0]);//display T
< Span style= "COLOR: #9876aa" > < Span style= "COLOR: #6a8759" > < Span style= "COLOR: #cc7832" > on the basis of the above improvements, using the array array to hold the queried data, the use for loop can manipulate the data < Span style= "COLOR: #6a8759" > < Span style= "COLOR: #6a8759" > < Span style= "color: #cc7832; Font-weight:bold ">
var New Array (); $ ("#leaf. Form-control option"). Map (function() { Array.push ($ (this). Text ( )); }) for (var i = 0; i < array.length; i + + ) { alert (array[i]);//Displays the text text1,text2 of each option , Text3 }
< Span style= "COLOR: #ffc66d" > < Span style= "COLOR: #6a8759" > < Span style= "COLOR: #ffc66d" >&NBSP;
JQuery Gets the text content of multiple Select label option