• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Angel----部落阁
Xcode10
博客园    首页    新随笔    联系   管理    订阅  订阅
js下拉框(select)联动

<form name="frm">
<select name="s1" size="1" onChange="redirec1(document.frm.s1.options.selectedIndex)">
 <option selected >浙江</option>
 <option >江苏</option>
</select>

<select name="s2" size="1" onChange="redirec2(document.frm.s1.options.selectedIndex,document.frm.s2.options.selectedIndex)">
 <option selected>杭州</option>
<option>金华</option>
</select>

<select name="s3" size="1">
 <option selected>富阳</option>
<option>萧山</option>
</select>
</form>
<script language="javascript">
var select2 = new Array(new Array(new Option("杭州"),new Option("金华")),new Array(new Option("苏州"),new Option("连云港")));
var select3 = new Array(new Array(new Array(new Option("富阳"),new Option("萧山")),new Array(new Option("永康"),new Option("义务"))),new Array(new Array(new Option("aa"),new Option("aaa"),new Option("aaaa"),new Option("aaaaa")),new Array(new Option("bb"),new Option("bbb"))));
function redirec1(x)
{
 var temp = document.frm.s2;
temp.length=0
 for (i=0;i<select2[x].length;i++)
 {
  temp.options[i]=new Option(select2[x][i].text);
 }
redirec2(document.frm.s1.options.selectedIndex,document.frm.s2.options.selectedIndex)

}

function redirec2(x,y)
{
 var temp = document.frm.s3;
temp.length=0
 for (i=0;i<select3[x][y].length;i++)
 {
  temp.options[i]=new Option(select3[x][y][i].text);
 }
}
</script> 

 
posted on 2008-06-19 14:40  angelfeather  阅读(5661)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3