[Note]select城市选择

来源:互联网 发布:电视机软件下载 编辑:程序博客网 时间:2024/06/15 19:02
<img id="tu" src="1.jpg" height=100><select name="sel" onchange="test(this)"><option value="1.jpg">one</option><option value="2.jpg">two</option><option value="3.jpg">three</option><option value="4.jpg">four</option></select><script>var tu=document.getElementById("tu");function test(obj){var index=obj.selectedIndex;tu.src=obj.options[index].value;}</script><!------------------------城市选择实例----------------------------------><!-Demo.html file---><script src="city.js"></script><script>scity("prop","cit");</script><!--city.js file--->var province=['北京','上海','陕西'];var citys=new Array(new Array("北京");new Array("上海");new Array("西安","宝鸡","咸阳"););function scity(pname,cname){document.write('<select id="pro" onchange="selectc(this)" name="'+pname+'">');document.write('<option value="">--选择省份--</option>');for(var i=0;i<province.length;i++){document.write('<option value="'+province[i]+'">'+province[i]+'</option>')}document.write('</select>');document.write('<select id="city" name="'+cname+'">');document.write('<option value="">--选择城市--</option>');document.write('</select>');selectc(document.getElementById("pro"));}function selectc(pobj){var index=proj.selectedIndex-1;var cobj=document.getElementById("city");cobj.innerHTML=""if(index>=0){for(var i=0;i<citys[index].length;i++){var option=document.createElement("option");var text=citys[index][i];option.value=text;option.innerHTML=text;cobj.appendChild(option);}}else{var option=document.createElement("option");option.value="";option.innerHTML="--选择城市--";cobj.appendChild(option);}}

原创粉丝点击