怎么用easyui创建两个依赖下拉框 省市联动 不走后台
<tr><tdclass="tdlft">所属城市</td><td><selectid="jia1"onchange="setjia2()"class="easyui-c...
<tr>
<td class="tdlft">所属城市</td>
<td><select id="jia1" onchange="setjia2()"
class="easyui-combobox" name="dept" style="width: 200px">
</select></td>
</tr>
<tr>
<td class="tdlft">所属县</td>
<td><select id="jia2" class="easyui-combobox" name="dept"
style="width: 200px">
</select></td>
<script language="javascript">
var dat = [
["山东","济南","青岛","潍坊","淄博","济宁","烟台"],
["辽宁","沈阳","大连","鞍山","葫芦岛","丹东"],
["北京","东城区","西城区","海淀区","朝阳区","昌平区"],
["上海","黄浦区","宝山区","嘉定区","浦东新区","虹口区"]
];
var jia1 = document.getElementById("jia1");
var jia2 = document.getElementById("jia2");
for(var i=0; i<dat.length; i++){
jia1.add(new Option(dat[i][0]));
}
(function setjia2(){
jia2.length = 0;
var dat2 = dat[jia1.selectedIndex];
for(var i=1; i<dat2.length; i++){
jia2.add(new Option(dat2[i]));
}
})();
</script>
</tr> 展开
<td class="tdlft">所属城市</td>
<td><select id="jia1" onchange="setjia2()"
class="easyui-combobox" name="dept" style="width: 200px">
</select></td>
</tr>
<tr>
<td class="tdlft">所属县</td>
<td><select id="jia2" class="easyui-combobox" name="dept"
style="width: 200px">
</select></td>
<script language="javascript">
var dat = [
["山东","济南","青岛","潍坊","淄博","济宁","烟台"],
["辽宁","沈阳","大连","鞍山","葫芦岛","丹东"],
["北京","东城区","西城区","海淀区","朝阳区","昌平区"],
["上海","黄浦区","宝山区","嘉定区","浦东新区","虹口区"]
];
var jia1 = document.getElementById("jia1");
var jia2 = document.getElementById("jia2");
for(var i=0; i<dat.length; i++){
jia1.add(new Option(dat[i][0]));
}
(function setjia2(){
jia2.length = 0;
var dat2 = dat[jia1.selectedIndex];
for(var i=1; i<dat2.length; i++){
jia2.add(new Option(dat2[i]));
}
})();
</script>
</tr> 展开
1个回答
2015-09-29
展开全部
省一个数组、市是二维数组、区是另一个二维数组
省点击后,显示对应的市的
市选中后,显示对应的区的
省点击后,显示对应的市的
市选中后,显示对应的区的
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询