jquery省市區三級聯動

效果圖: 

 

效果圖

源代碼:

  1.  
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
  4. <html> 
  5. <head> 
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  7. <title>Insert title here</title> 
  8. </head> 
  9. <body> 
  10. <div> 
  11. <h4>三級聯動:</h4> 
  12. <select id="s1"> 
  13.     <option value="">請選擇</option> 
  14. </select> 
  15. <select id="s2"> 
  16.     <option value="">請選擇</option> 
  17. </select> 
  18. <select id="s3"> 
  19.     <option value="">請選擇</option> 
  20. </select> 
  21. </div> 
  22. <input type="button" id="btn1" value="聚焦到德清縣"> 
  23. <input type="button" id="btn2" value="聚焦到上城區"> 
  24. <div> 
  25. <h4>二級聯動:</h4> 
  26. <select id="a1"> 
  27.     <option value="">請選擇</option> 
  28. </select> 
  29. <select id="a2"> 
  30.     <option value="">請選擇</option> 
  31. </select> 
  32. </div> 
  33.              
  34. <input type="button" id="btn3" value="聚焦到杭州市"> 
  35. <input type="button" id="btn4" value="聚焦到紹興市"> 
  36. <script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script> 
  37. <script type="text/javascript" src="js/tdist.js"></script> 
  38. <script type="text/javascript" src="js/cityselect.jquery.js"></script> 
  39. <script type="text/javascript"> 
  40. (function($){ 
  41.     var sel = new $.CitySelect({ 
  42.         targets:["#s1","#s2","#s3"] 
  43.     });  
  44.  
  45.     $("#btn1").click(function(){ 
  46.         sel.focus(2,"330521"); 
  47.     }); 
  48.  
  49.     $("#btn2").click(function(){ 
  50.         sel.focus(2,"330102"); 
  51.     }); 
  52.  
  53.      
  54.     var sel2 = new $.CitySelect({ 
  55.         targets:["#a1","#a2"] 
  56.     });  
  57.  
  58.     $("#btn3").click(function(){ 
  59.         sel2.focus(1,"330100"); 
  60.     }); 
  61.     $("#btn4").click(function(){ 
  62.         sel2.focus(1,"330600"); 
  63.     }); 
  64.      
  65. })(jQuery); 
  66.  
  67. </script> 
  68.  
  69. </body> 
  70. </html> 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章