<!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>
  <title> new document </title>
  <script type="text/javascript">
  <!--
function bindBranch(){
var branchList = ["one","two","three","four"];
var osel = document.getElementById("ddlBranch").options;
for(var i = 0;i < branchList.length;i++){
osel.add(new Option(branchList[i],branchList[i]))
}
}
  //-->
  </script>
 </head> <body>
  <select id = "ddlBranch"></select>
  <input type="button" onclick="bindBranch()" value="create" />
 </body>
</html>自己参考下

解决方案 »

  1.   


    谢谢~~我想问一下new Option(branchList[i],branchList[i])中间的两个参数表示什么?
    我这样写document.getElementById("ddlBranch").options.add(new Option(branchList[i].name,branchList[i].id)); 
    我运行出来了,但是报错,说branchList[i].name不是对象
      

  2.   

    百度了一下
    javascript:new Option(text, value)
    谢谢