jquery dynamic method of adding and traversing option

Source: Internet
Author: User
This time to bring you the jquery dynamic Add and traverse option, jquery dynamic add traversal option of the note what, the following is the actual case, take a look.

The examples are as follows:

<pre name= "code" class= "HTML" ><script type= "Text/javascript" src= " Http://code.jquery.com/jquery-latest.js "></script> <select class=" Form-control "id= ' Selectid ' > < Option class= "All" value= "0" > Full </option> <option class= "All" value= "1" >os2</option> <option >os2-anthonos</option> <option>os2-apps</option> <option>os2-centralpoint</option > <option>kf5-experimental</option> </select> <script>//Dynamically add Option//$ ("#selectId").  Append ("<option value= '" +value+ ">" +text+ "</option>");  $ (document). Ready (function () {var string = ""; $ ("#selectId option"). each (function () {//Traversal all option var text = $ (this). text ();//Gets the text var of option = $ (this). Val () ;  Gets the value of option if ($ (this). attr ("class") = = "All") string + = "{" +text+ ":" +value+ "}";  }); Alert (string.substring (0,string.length)); }); </script> 

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

ANGULAR2 Parent-Child component communication mode

JavaScript code optimization in detail

360 Browser Compatibility Mode page display does not completely how to deal with

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.