<!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=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function aa()
{
var ivrs="aa,bb,cc,dd,ee"; //这是从后台传过来的不定数量
var ivrArray = ivrs.split(",");
     for(var i = 0; i < ivrArray.length; i++){  
   var ivr=ivrArray[i];  //ivr 
   alert(ivr);   //怎么把ivr 放到 select 里呀
   }
   
   }
</script>
<body onload="aa();">
<select name="ivrname">
  <option value="aa">aa</option>
  <option value="bb">bb</option>  </select>
</body>
</html>

解决方案 »

  1.   

    var y=document.createElement('option');
    y.text='aa';
    y.value='aa';
    document.getElementsByName("ivrname")[0].add(y);
      

  2.   


    function aa()
    {
           var ivrs="aa,bb,cc,dd,ee"; //这是从后台传过来的不定数量
           var ivrArray = ivrs.split(",");
           var select = document.getElementsByName("ivrname")[0];
           for(var i = 0; i < ivrArray.length; i++){  
               var ivr=ivrArray[i];  //ivr 
               var tmp = document.createElement("option");
               tmp.value=ivr;
               tmp.text=ivr;
               select.add(tmp);
           }   
    }
      

  3.   

    <!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=gb2312" />
    <title>无标题文档</title>
    </head>
    <script language="javascript">
    function aa()
    {
    var ivrs="aa,bb,cc,dd,ee"; //这是从后台传过来的不定数量
    var ivrArray = ivrs.split(",");
             for(var i = 0; i < ivrArray.length; i++){  
       var ivr=ivrArray[i]; 
       var opt = document.createElement("option");
        opt.value = opt.text = ivr;
          document.getElementsByName("ivrname")[0].appendChild(opt);
       }
       
       }
    </script>
    <body onload="aa();">
    <select name="ivrname">
      <option value="aa">aa</option>
      <option value="bb">bb</option>  </select>
    </body>
    </html>
      

  4.   

    opt.value = opt.text = ivr;
    ==》
    opt.value = opt.innerHTML = ivr;
    上边的ie不支持
      

  5.   

    怎么把 value 也加上呀