爱4妮 jQuery + Ajax + json 级联省市县级联
2012-05-07 18:51
357 查看
$(function (){ var sf = $(".carname").children("select"); var cy = $(".cartype").children("select"); var dx = $(".wheeltype").children("select"); var carimg = $(".carimg"); sf.change(function (){ var pid =$(this).val(); carimg.hide(); dx.parent().hide(); //省份不为空 if(pid !=""){ $.get("http://domain:8080/test/CardServlet?method=getcity&pids="+pid,function (data) { if(data.length !=0) { cy.html(""); $("<option value=''>请选择城市</option>").appendTo(cy); $.each(data,function(index,city) { $("<option value='"+city.cid+"'>" +city.cname + "</option>").appendTo(cy); }); cy.parent().show(); sf.next().show(); } },"json"); } //省份为空 else{ cy.parent().hide(); sf.next().hide(); } }); //城市下拉框 cy.change(function (){ var cid =$(this).val(); dx.parent().show(); carimg.hide(); //城市不为空 if(cid !=""){ $.get("http://domain:8080/test/CardServlet?method=getarea&cids="+cid,function (data) { if(data.length !=0) { dx.html(""); $("<option value=''>请选择地区</option>").appendTo(dx); $.each(data,function(index,aper) { $("<option value='"+aper.aid+"' >" +aper.aname + "</option>").appendTo(dx); }); dx.parent().show(); cy.next().show(); } else{ dx.parent().hide(); cy.next().hide(); } },"json"); } //省份为空 else{ dx.parent().hide(); cy.next().hide(); } }); dx.change(function(){ var dqm = $(this).val(); //2.根据省份 城市 地区 获得 图片的文件名 var sfm = sf.val(); var csm = cy.val(); var carimgname =sfm+csm+dqm+".jpg"; alert( carimgname); carimg.hide(); $(".carloading").show(); //4.通过Javascript中的Image对象预装载图片 var cacheimg = new Image(); $(cacheimg).attr("src","images/" + carimgname).load(function(){ //隐藏loading图片 $(".carloading").hide(); //显示图片 carimg.attr("src","images/" + carimgname).show(); }); }); //给数据装载中的节点定义ajax事件,实现动画提示效果 $(".loading").ajaxStart(function(){ $(this).css("visibility","visible"); $(this).animate({ opacity: 1 },0); }).ajaxStop(function(){ $(this).animate({ opacity: 0 },500); }); }); </script>
相关文章推荐
- 省市级联基于jquery+json(转)
- JS—我的第五个AJAX程序(省市级联、JSON传递)
- jquery+json+ajax省市二级联动下拉
- jquery调取json数据实现省市级联的方法
- 省市级联--jquery调取json数据
- Ajax实现下拉框级联(在servlet中把从数据库取出来的值以json形式返回ajax,用jquery遍历便利更新<option>的值)
- hibernate中关于servlet+Ajax+jquery+json+gson实现级联效果
- jquery调取json数据实现省市级联的方法
- ASP.NET基于JQUERY的AJAX的验证登录(JSON)
- jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- Jquery 使用Ajax获取后台返回的Json数据后,页面处理
- Jquery发送ajax请求以及datatype参数为text/JSON方式
- jQuery中使用Ajax获取JSON格式数据示例代码
- jquery中ajax向action传递对象参数,json ,spring注入对象
- 玩玩AJAX之使用ashx文件响应来自JQuery的JSON请求
- jquery json ajax
- jQuery+ajax实现无刷新级联菜单示例
- JQuery处理json与ajax返回JSON实例
- ECharts SSH+JQueryAjax+Json+JSP在数据库中的数据来填充ECharts在
- servlet+jquery+ajax+json 例子