用js动态添加select标签的option

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>


猜你喜欢

转载自blog.csdn.net/m0_37148591/article/details/76162480