258197205 发表于 2013-2-7 16:02:45

jQuery二级联动

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""">
<html>
<head>
   <title>无标题页</title>
   <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
   <script src="jquery.js" type="text/javascript"></script>
   <style type="text/css">
       .sub{display:none;}
   </style>
</head>
<body>
<script type="text/javascript">
       $(document).ready(function(){
           $("#sel1").change(function(){
               $("#sel1 option").each(function(i,o){
                   if($(this).attr("selected"))
                   {
                       $(".sub").hide();
                       $(".sub").eq(i).show();
                   }
               });
           });
           $("#sel1").change();
       });
   </script>
   <select id="sel1">
       <option>北京</option>
       <option>安徽省</option>
   </select>
   <select class="sub">
       <option>中关村</option>
       <option>朝阳区</option>
   </select>  
   <select class="sub">
       <option>合肥</option>
       <option>安庆</option>
   </select>
 
</body>
</html>
页: [1]
查看完整版本: jQuery二级联动