现在的位置: 首页 > 综合 > 正文

Ajax 实现省市县 三级联动【无刷新】三层 | 三级联动—有刷新

2012年04月11日 ⁄ 综合 ⁄ 共 3219字 ⁄ 字号 评论关闭

SQL建表

HTML——HTMLPage1.htm

[html] view
plain
copy

  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head>  
  3.     <title>Ajax 实现省市县 三级联动【无刷新】三层</title>  
  4.     <style type="text/css">  
  5.         select  
  6.         {  
  7.             width: 130px;  
  8.         }  
  9.     </style>  
  10.     <script src="js/Jquery1.7.js" type="text/javascript"></script>  
  11.     <script type="text/javascript">  
  12.         $(function () {  
  13.             $.ajax({  
  14.                 type: "post",  
  15.                 contentType: "application/json",  
  16.                 url: "WebService1.asmx/GetProvince",  
  17.                 data: "{}",  
  18.                 success: function (result) {  
  19.                     var stroption = '';  
  20.                     for (var i = 0; i < result.d.length; i++) {  
  21.                         stroption += '<option value=' + result.d[i].provinceID + '>';  
  22.                         stroption += result.d[i].provincename;  
  23.                         stroption += '</option>';  
  24.                     }  
  25.                     $('#seprovince').append(stroption);  
  26.                 }  
  27.             })  
  28.   
  29.             $('#seprovince').change(function () {  
  30.   
  31.                 $('#secity option:gt(0)').remove();  
  32.                 $('#searea option:gt(0)').remove();  
  33.   
  34.                 $.ajax({  
  35.                     type: "post",  
  36.                     contentType: "application/json",  
  37.                     url: "WebService1.asmx/GetCItyByPro",  
  38.                     data: "{proid:'" + $(this).val() + "'}",  
  39.                     success: function (result) {  
  40.                         var strocity = '';  
  41.                         for (var i = 0; i < result.d.length; i++) {  
  42.                             strocity += '<option value=' + result.d[i].cityID + '>';  
  43.                             strocity += result.d[i].cityname;  
  44.                             strocity += '</option>';  
  45.                         }  
  46.                         $('#secity').append(strocity);  
  47.                     }  
  48.                 })  
  49.             })  
  50.   
  51.             $('#secity').change(function () {  
  52.                 $('#searea option:gt(0)').remove();  
  53.                 $.ajax({  
  54.                     type: "post",  
  55.                     contentType: "application/json",  
  56.                     url: "WebService1.asmx/GetAreaByCity",  
  57.                     data: "{cityid:'" + $(this).val() + "'}",  
  58.                     success: function (result) {  
  59.                         var stroarea = '';  
  60.                         for (var i = 0; i < result.d.length; i++) {  
  61.                             stroarea += '<option value=' + result.d[i].areaID + '>';  
  62.                             stroarea += result.d[i].areaname;  
  63.                             stroarea += '</option>';  
  64.                         }  
  65.                         $('#searea').append(stroarea);  
  66.                     }  
  67.                 })  
  68.             })  
  69.         })  
  70.     </script>  
  71. </head>  
  72. <body>  
  73.     <table>  
  74.         <tr>  
  75.             <td>  
  76.                 用户名  
  77.             </td>  
  78.             <td>  
  79.                 <input id="Text1" type="text" />  
  80.             </td>  
  81.         </tr>  
  82.         <tr>  
  83.             <td>  
  84.                 密码  
  85.             </td>  
  86.             <td>  
  87.                 <input id="Text2" type="text" />  
  88.             </td>  
  89.         </tr>  
  90.         <tr>  
  91.             <

抱歉!评论已关闭.