加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax实现省,市,县的三级联动

发布时间:2020-12-15 21:00:03 所属栏目:百科 来源:网络整理
导读:!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" html head titlecity.html/title meta http-equiv="keywords" content="keyword1,keyword2,keyword3" meta http-equiv="description" content="this is my page" meta http-equiv="content-ty
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>city.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript"> /* [ {"id":110000,"leaf":false,"name":"北京市","parentId":0},{"id":120000,"name":"天津市",{"id":130000,"name":"河北省","parentId":0} ... ] */ // 不带缓存的实现 $(document).ready(function(){ $.post("/ajaxapp/city.do",{},function(json){ for(var i = 0; i < json.length; i++) { $("<option>").val(json[i].id).text(json[i].name).appendTo("#sheng"); } $("#sheng").change(); //主动触发change事件 },"json"); $("#sheng").change(function(){ $.post("/ajaxapp/city.do",{parentId:$(this).val()},function(json){ $("#shi").empty(); for(var i = 0; i < json.length; i++) { $("<option>").val(json[i].id).text(json[i].name).appendTo("#shi"); } $("#shi").change(); },"json"); }); $("#shi").change(function(){ $.post("/ajaxapp/city.do",function(json){ $("#xian").empty(); for(var i = 0; i < json.length; i++) { $("<option>").val(json[i].id).text(json[i].name).appendTo("#xian"); } },"json"); }); }); </script> </head> <body> <select id="sheng"></select> <select id="shi"></select> <select id="xian"></select> </body> </html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读