从数据字典读取省市信息

来源:互联网 发布:java 微秒 编辑:程序博客网 时间:2024/05/21 10:19
$.ajax({type: "post", //以post方式与后台沟通 url:"${pageContext.request.contextPath}/notBaseInfo/province", dataType:'json',//从php返回的值以 JSON方式 解释 ssuccess:function(json){$("#personAddressDiv .val").parent().append("<select id='countrySelect'></select>");//循环 省级元素$.each(json,function(i,item){$("#countrySelect").append("<option value='"+item.DICTNAME+"' name='"+item.DICTID+"'>"+item.DICTNAME+"</option>")})//获取第一值 获得省级数据 初始化的时候 var id=$("#countrySelect :first").attr("name");//当省级元素发生改变时$("#countrySelect").change(function(){var selectProvinceId=$(this).children('option:selected').attr("name");$.ajax({type: "post", //以post方式与后台沟通 data:"id="+selectProvinceId,url:"${pageContext.request.contextPath}/notBaseInfo/city", dataType:'json',success:function(json){$("#citySelect").empty(); //城市清空$("#regionSelect").empty();//县级清空$("#streetInfo").val("");//街道清空//输入市级$.each(json,function(i,item){$("#citySelect").append("<option value='"+item.DICTNAME+"' name='"+item.DICTID+"'>"+item.DICTNAME+"</option>")})//获取第一值 获得市级数据 var idCity=$("#citySelect :first").attr("name");//初始化县级元素$.ajax({type: "post", //以post方式与后台沟通 data:"id="+idCity,url:"${pageContext.request.contextPath}/notBaseInfo/region", dataType:'json',success:function(json){$.each(json,function(i,item){$("#regionSelect").append("<option value='"+item.DICTNAME+"' name='"+item.DICTID+"'>"+item.DICTNAME+"</option>")})},error:function(){}})//当城市改变时$("#citySelect").change(function(){var selectCityId=$(this).children('option:selected').attr("name");$.ajax({type: "post", //以post方式与后台沟通 data:"id="+selectCityId,url:"${pageContext.request.contextPath}/notBaseInfo/region", dataType:'json',success:function(json){$("#regionSelect").empty();//县级清空$("#streetInfo").val("");//街道清空$.each(json,function(i,item){$("#regionSelect").append("<option value='"+item.DICTNAME+"' name='"+item.DICTID+"'>"+item.DICTNAME+"</option>")})return;},error:function(){//city change}})})},error:function(){//province change;}})})//初始化市级元素$.ajax({type: "post", //以post方式与后台沟通 data:"id="+id,url:"${pageContext.request.contextPath}/notBaseInfo/city", dataType:'json',//success:function(json){$("#personAddressDiv .val").parent().append("<select id='citySelect'></select>");$.each(json,function(i,item){$("#citySelect").append("<option value='"+item.DICTNAME+"' name='"+item.DICTID+"'>"+item.DICTNAME+"</option>")})//获取第一值 获得市级数据 var idCity=$("#citySelect :first").attr("name");//初始化县级元素$.ajax({type: "post", //以post方式与后台沟通 data:"id="+idCity,url:"${pageContext.request.contextPath}/notBaseInfo/region", dataType:'json',success:function(json){$("#personAddressDiv .val").parent().append("<select id='regionSelect'></select>");$.each(json,function(i,item){$("#regionSelect").append("<option value='"+item.DICTNAME+"' name='"+item.DICTID+"'>"+item.DICTNAME+"</option>")})//添加最后的街道输入$("#personAddressDiv .val").parent().append("<input type='text' id='streetInfo'/>");}})//当市级元素改变时$("#citySelect").change(function(){var selectCityId=$(this).children('option:selected').attr("name");$.ajax({type: "post", //以post方式与后台沟通 data:"id="+selectCityId,url:"${pageContext.request.contextPath}/notBaseInfo/region", dataType:'json',success:function(json){$("#regionSelect").empty();//县级清空$("#streetInfo").val("");//街道清空$.each(json,function(i,item){$("#regionSelect").append("<option value='"+item.DICTNAME+"' name='"+item.DICTID+"'>"+item.DICTNAME+"</option>")});return;},error:function(){}})})},error:function(){}})},error:function(){}})

这个需要三步

1.初始化省市县

2,省变 市县初始化

3省不变 市变,县初始化

0 0
原创粉丝点击