<!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=utf-8" /><title>无标题文档</title><script>function getCity(){ var privince=document.getElementById("province"); var city=document.getElementById('city'); var shu=privince.selectedIndex;alert(shu);/*if 语句 - 只有当指定条件为 true 时,使用该语句来执行代码if...else 语句 - 当条件为 true 时执行代码,当条件为 false 时执行其他代码*/switch(shu){ case 1: city.options.length=0; city.add(new Option("朝阳","朝阳")); city.add(new Option("朝阳","朝阳")); city.add(new Option("朝阳","朝阳")); break; case 2: city.options.length=0; city.add(new Option("东莞","东莞")); city.add(new Option("东莞","东莞")); city.add(new Option("东莞","东莞")); break default: city.options.length=0; city.add(new Option("辽宁","辽宁")); city.add(new Option("辽宁","辽宁")); city.add(new Option("辽宁","辽宁")); }}</script></head><body> <FORM METHOD=POST ACTION="" name="form1"> <select name="province" id="province" onchange="getCity()" > <option selected="selected">请选择所在省份</option> <option >北京</option><option value="广州">广州</option><option value="山东">山东</option></select><select id="city" name="city" ></select></FORM></body></html>
添加回答
举报
0/150
提交
取消