<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>二级下拉菜单联动实例</title>
</head>
<body>
<select id="first" onChange="change()">
<option selected="selected">湖北</option>
<option>广东</option>
</select>
<select id="second">
<option>黄冈</option>
<option selected="selected">武汉</option>
</select>
<script>
function change()
{
var x = document.getElementById("first");
var y = document.getElementById("second");
y.options.length = 0; // 清除second下拉框的所有内容
if(x.selectedIndex == 0)
{
y.options.add(new Option("黄冈", "0"));
y.options.add(new Option("武汉", "1", false, true)); // 默认选中省会城市
}
if(x.selectedIndex == 1)
{
y.options.add(new Option("深圳", "0"));
y.options.add(new Option("广州", "1", false, true)); // 默认选中省会城市
y.options.add(new Option("肇庆", "2"));
}
}
</script>
</body>
</html>
html js 二级菜单联动
最新推荐文章于 2022-12-08 19:42:52 发布