代码--神奇的城市(模拟省份下自动调出城市)

<!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 type="text/javascript">
 function fun1(){
     var A=document.myform.myselect;
     var B=A.selectedIndex;
     if(B==1 ||B==2 || B==3 || B==4)
     document.myform.city.value=A.options[B].text;
     }
 function fun2(){
    var names=document.myform.names.value;
    var province=document.myform.myselect.value ;
    var city=document.myform.city.value ;
    document.write("<body bgColor=#ffffoo>");
    document.write("<h1>您的注册信息如下:</h1>");
    document.write("<hr>");
    document.write("<P><h3>姓名:</h3>"+names);
    document.write("<P><h3>帐号开户省份:</h3>"+province);
    document.write("<P><h3>帐号开户城市:</h3>"+city);
     }    
</script>
</head>

<body bgcolor="teal">
<form name="myform">
<table width="666"  border="0" cellpadding="0" cellspacing="o" align="center" bgcolor="pink">
  <tr>
    <td colspan="2"><img src="images/1.gif"><img src="images/2.gif"></td>
    
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>

  </tr>
  <tr>
    <td width="77"><h2>姓名:</h2></td>
    <td width="589"><input type="text" name="names" value=""></td>
  </tr>
  <tr>
    <td><h2>省份:</h2></td>
    <td><select name="myselect" size="2" onChange="fun1( )">
      <option>--请选择开户帐号的城市--</option>
      <option value="北京市">北京市</option>
      <option value="上海市">上海市</option>
      <option value="重庆市">重庆市</option>
      <option value="天津市">天津市</option>
      <option value="四川省">四川省</option>
      <option value="山东省">山东省</option>
      <option value="湖北省">湖北省</option>
                        </select></td>
  </tr>
  <tr>
    <td><h2>城市:</h2></td>
    <td><input type="text" name="city" value=""></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>

  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><img src="images/reg.bmp" onClick="fun2()"></td>
  </tr>
</table>
</form>
</body>
</html>


posted @ 2012-05-16 18:55  yangkai_keven  阅读(185)  评论(0编辑  收藏  举报