HTML代码
<select name="" value="" id="subselect"> <option id="sub" value="请选择商圈">请选择商圈</option> </select>
先引入JQ库
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"></script>
jquery代码如下
$('#select').bind('change', function () { var value = $('#select').val(); if (value === '大兴') { var city = ["采育镇", "国家新媒体产业基地", "黄村卫星城", "京开高速", "旧宫", "庞各庄", "生物医药基地", "首都第二机场", "天宫院", "魏善庄", "西红门", "亦庄", "瀛海",]; $("#subselect").empty(); var arrayLength = city.length;// 数组的长度 //当i<arrayLength时,可以按顺序访问数组中的值 for (var i = 0; i < arrayLength; i++) { var B = city[i];//调用数组中的值 println(B) } function println(a) { $("#subselect").append("<option value='+a+'>" + a + "</option>") } } });