jquery動態添加和遍曆option的方法

來源:互聯網
上載者:User
這次給大家帶來jquery動態添加和遍曆option的方法,jquery動態添加遍曆option的注意事項有哪些,下面就是實戰案例,一起來看一下。

執行個體如下所示:

<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">全部</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>  //動態添加option  //$("#selectId").append("<option value='"+value+"'>"+text+"</option>");  $(document).ready(function(){  var string = "";  $("#selectId option").each(function(){ //遍曆全部option  var text = $(this).text(); //擷取option的text  var value = $(this).val(); //擷取option的value  if($(this).attr("class")=="all")   string +="{"+text+":"+value+"}";  });  alert(string.substring(0,string.length)); }); </script>

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

Angular2 父子組件通訊方式

javascript的代碼最佳化詳解

360瀏覽器安全色模式的頁面顯示不全怎麼處理

相關文章

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.