用js動態新增select標籤的option
阿新 • • 發佈:2018-11-16
js程式碼:
var featureLayerURLTest=[["http://192.168.15.174:6080/arcgis/rest/services/Sample/GQYDGH/FeatureServer/0","線圖層1"]]; function createSelectOption(featureLayerURLTest){ var _html=""; for(var _i=0;_i<featureLayerURLTest.length;_i++){ _html=_html+"<option value='"+featureLayerURLTest[_i][0]+"'>"+featureLayerURLTest[_i][1]+"</option>"; } $("#featureLayerOptions").append(_html); var html=$("#featureLayerOptions"); //console.log(html); } $(function(){ createSelectOption(featureLayerURLTest); });
html程式碼:
<div>
<lable>選擇操作圖層:</lable>
<br/>
<select id="featureLayerOptions">
<option id="defaultOption" value="0">
請選擇操作圖層
</option>
</select>
</div>