我对js不是很熟悉, 现在要做一个 三级联动 省 市 区 大神来帮忙 讲解下 思路, 最好是代码实现
JavaScript
------解决方案--------------------
联动的思路很简单,
就是change事件里发ajax请求,传参数,回调函数里根据响应更新选项
具体代码你得自己写
------解决方案--------------------
1.创建3个下拉框,ddlProvince,ddlCity,ddlTown
2.页面加载时将省份的数去取唯一填充ddlProvince:select distinct(province) from table
3.ddlProvince发生change事件时,根据值区市数据填充ddlCity:select distinct(city) from table where province='ddlProvince选中值'
4.ddlCity发生change事件时,根据选中省、市值取数据填充ddlTowun:
select distinct(town) from table where province='ddlProvince选中值' and city='ddlCity选中值'
------解决方案--------------------
<script src="js/provincesCity.js" type="text/javascript"></script>
<select id="sheng" name="sheng"><option>--请选择--</option></select>
<select id="shi" name="shi"><option>--请选择--</option></select>
<select id="xian" name="xian"><option>--请选择--</option></select>
function getXmlDoc(url) {
var xmlDoc;
try {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
catch (e) {
try {
var oXmlHttp = new XMLHttpRequest();
oXmlHttp.open("GET", "js/province_city.xml", false);
oXmlHttp.send(null);
return oXmlHttp.responseXML;
} catch (e) {
return;
}
}