JQuery gets the text content of multiple Select label option

Source: Internet
Author: User

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

Related Article

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.