<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>每天一个JavaScript实例-动态省份选择城市</title> <script> var citystore = new Array(); citystore = [['SD','济南'],['SD','烟台'],['SD','青岛'],['SX','太原'],['BJ','北京'],['HN','海南']]; window.onload = function(){ document.getElementById("state").onchange=changecity; } function changecity(){ var state = this.value; var city = document.getElementById('cities'); city.options.length = 0; for(var i = 0; i <citystore.length;i++){ if(state == citystore[i][0]){ var opt =new Option(citystore[i][1]); try{ city.add(opt,null); }catch(e){ city.add(opt); } } } } </script> </head> <body> <form id="picker" method="post" action=""> <select id = "state"> <option value="">--</option> <option value="SD">山东</option> <option value="SX">山西</option> <option value="BJ">北京</option> <option value="HN">海南</option> </select> <select id="cities"> </select> </form> </body> </html>