js省份城市初始化
阿新 • • 發佈:2019-03-02
var provinceObj = document.getElementById("province").options; for (var i=0; i<provinceObj.length; i++) { if (provinceObj[i].value == province) { provinceObj[i].selected = true; break; } } var pname = pro_select.value; city_select.innerHTML = "<option>--選擇市--</option>"; //遍歷城市列表 for (var j in city) { if (pname == city[j].pname) { var opt = document.createElement("option"); opt.innerText = city[j].cname; opt.setAttribute("value", city[j].cname); city_select.appendChild(opt); } } var city1 = '${data.city!}'; //Struts2中從實體中取值 var cityObj = document.getElementById("city").options; for (var i=0; i<cityObj.length; i++) { if (cityObj[i].value == city1) { cityObj[i].selected = true;