jQuery 二级联动 非ajax 优点是结构非常简单
XML/HTML Code
- <select id="province">
- <option>----请选择省份----</option>
- <option>北京</option>
- <option>上海</option>
- <option>江苏</option>
- </select>
- <select class="city">
- <option>----请选择城市----</option>
- </select>
- <select class="city">
- <option>东城</option>
- <option>西城</option>
- <option>崇文</option>
- <option>宣武</option>
- <option>朝阳</option>
- </select>
- <select class="city">
- <option>黄浦</option>
- <option>卢湾</option>
- <option>徐汇</option>
- <option>长宁</option>
- <option>静安</option>
- </select>
- <select class="city">
- <option>南京</option>
- <option>镇江</option>
- <option>苏州</option>
- <option>南通</option>
- <option>扬州</option>
- </select>
JavaScript Code
- <script type="text/javascript">
- var currentShowCity=0;
- $(document).ready(function(){
- $("#province").change(function(){
- $("#province option").each(function(i,o){
- if($(this).attr("selected"))
- {
- $(".city").hide();
- $(".city").eq(i).show();
- currentShowCity=i;
- }
- });
- });
- $("#province").change();
- });
- function getSelectValue(){
- alert("1级="+$("#province").val());
- $(".city").each(function(i,o){
- if(i == currentShowCity){
- alert("2级="+$(".city").eq(i).val());
- }
- });
- }
- </script>
原文地址:http://www.freejs.net/article_jiaodiantu_374.html