动态显示下拉框的值

<!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>动态的添加和移除select的option选项</title>
 <script type="text/javascript">
 function removeAndAddOption(v){
  var sels = document.getElementById("select1");
  for(var i=sels.length-1;i > 0;i--){
   sels.removeChild(sels.options[i]);
  }
  var max = 0;
   switch(v){
    case '1' :
    max = 10;
    break;
    case '2' :
    max = 20;
    break;
    case '3' :
    max = 30;
    break;
    case '4' :
    max = 40;
    break;
    case '5' :
    max = 50;
    break;
   }
  for(var i=0;i<max;i++){
   sels.options[i] = new Option(i,i);
  }
 }
 </script>
</head>
<body>
 <select onchange="removeAndAddOption(this.value)">
  <option value="1">1111111</option>
  <option value="2">2222222</option>
  <option value="3">3333333</option>
  <option value="4">4444444</option>
  <option value="5">5555555</option>
 </select>
 <br />
 <select id="select1">
 <SCRIPT>document.write(" <option value=\" removeAndAddOption() .\">"); </SCRIPT>
 </select>
</body>
</html>

你可能感兴趣的:(职场,动态,休闲)