欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java json 省市级联实例代码

程序员文章站 2023-12-20 22:11:34
复制代码 代码如下://     获取国家省市区信息$(document).ready(function(){ //从程序获取js...

复制代码 代码如下:

//     获取国家省市区信息
$(document).ready(function(){

//从程序获取json格式的数据
var info = $request.getattribute("manualorderareainfo");


var provinceinfo = $("#provinceid");
var cityid = $("#cityid");

//清空信息
provinceinfo.empty();

//循环获取信息
$.each(info.area, function(idx,item){
if(idx == 0){
return true;
}
//alert("name:"+idx+",areaid:"+item.areaid+",areaname:"+item.areaname+",areaparentid:"+item.parentid);

//这里父类id为1是城市信息
if(item.parentid == 1){
$("<option value="+item.areaid+">"+item.areaname+"</option>").appendto(provinceinfo);
}
});
//获取对应的城市信息
$("#provinceid").change(function(){
var tempinfo = $("#provinceid").val();
cityid.empty();
$.each(info.area, function(indexinfo,item){
if(indexinfo == 0){
return true;
}
if(item.parentid == tempinfo){
$("<option value="+item.areaid+">"+item.areaname+"</option>").appendto(cityid);
}
});
});
});

复制代码 代码如下:

<tr>
                    <th style="width:120px;">收货人省份</th>
<!--                    <td style="width:270px;"><input type="text" value="$!{manualentryorder.goodreceiverprovince}" name="manualentryorder.goodreceiverprovince" style="width:150px;"  maxlength="255"/></td>-->
                        <td style="width: 270px;">
                            <select id="provinceid" name="staffprovince" style="width: 154px;">
                            </select>

                        </td>
                    <th style="width:140px;">收货人城市</th>
                    <td style="width:270px;">
<!--                        <input type="text" value="$!{manualentryorder.goodreceivercity}" name="manualentryorder.goodreceivercity" style="width:150px;"  maxlength="255"/>-->
                            <select id="cityid" name="staffprovince" style="width: 154px;">
                                <option value="--">---请选择城市信息---</option>
                            </select>
                    </td>
                </tr>

上一篇:

下一篇: