日期:2014-05-16  浏览次数:20987 次

省市区三级联动的代码,怎么修改让它获取初始值呢
省市区三级联动的代码,怎么修改让它获取初始值呢
<script type="text/javascript" src="get3j.js"></script>
<select id="sp" name ="sp"onChange="chgProvinces('sp','sc','sa')">
        <option></option>
    </select>
    <select id="sc" name ="sc"onChange="chgCitys('sc','sa')">
        <option></option>
    </select>
    <select id="sa" name ="sa" >
        <option></option>
    </select>
<script type="text/javascript">
loadData('sp', 'sc', 'sa');
</script>

------解决方案--------------------
将原代码的三个javascript函数分别替换为:

        function getProvinces(spid) {
            var sp = document.getElementById(spid);
            sp.options.length = 0;

            var pAs = provincesData.split(",");

var i=-1,j=0
            for (var pA in pAs) {
                var pA_parts = pAs[pA].split("
------解决方案--------------------
");
                sp.options.add(new Option(pA_parts[1], pA_parts[0]));
i=i+1
if (pA_parts[1]=="<%=request.querystring("p")%>"){j=i}
            }

            if (sp.options.length == 0) {
                sp.disabled = true;
                sp.options.add(new Option("", "000000"));
            }
            else {
                sp.disabled = false;
            }

            sp.options[j].selected = true;
        }

        function getCitys(scid, spid) {
            var sc = document.getElementById(scid);
            sc.options.length = 0;

            var sp = document.getElementById(spid);
            var pv = sp.options[sp.selectedIndex].value;

           &