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