window.parent.form1.deptsel.options[toLength]=new Option("Hello","lllll");

解决方案 »

  1.   

    window.opener.document.form1.deptsel.options[toLength]=new Option('hello','11111')
      

  2.   

    //-- 变通一下
    test1.html<script language=javascript>
      function btnTest_onclick(){
        form1.deptsel.options[0]=new Option('hello1','bds1');
        form1.deptsel.options[1]=new Option('hello2','bds2');
        form1.deptsel.options[2]=new Option('hello3','bds3');
      }  function btnTest2_onclick(){
        window.open("test2.html");
      }  function funcTest(){
        alert("I love this game !");
      }
    </script>
    <form name=form1>
    <table border=1 align=center>
      <tr>
        <td>
      <select name=deptsel>
        <option value="value1">value1</option>
        <option value="value2">value2</option>
        <option value="value3">value3</option>
      </select>
    </td>
      </tr>
    </table>
    <input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();">
    <input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();">
    <input type="button" name=btnTest3 value="测 试3" onclick="funcTest();">
    </form>
    //******************************************************************
    test2.html
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    </head>
    <body><button onclick=test()>test</button>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function test()
    {
      window.opener.btnTest_onclick();
    }
    //-->
    </SCRIPT>
    </body>
    </html>
      

  3.   

    test2.html<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    </head>
    <body><button onclick=test()>test</button>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function test()
    {
      window.opener.btnTest_onclick();
    }
    //-->
    </SCRIPT>
    </body>
    </html>
    //**************************************************************
    test3.html
    <script language=javascript>
      function btnTest_onclick(){
        form1.deptsel.options[0]=new Option('hello1','bds1');
        form1.deptsel.options[1]=new Option('hello2','bds2');
        form1.deptsel.options[2]=new Option('hello3','bds3');
      }  function btnTest2_onclick(){
        window.open("test2.html");
      }  function funcTest(){
        alert("I love this game !");
      }
    </script>
    <form name=form1>
    <table border=1 align=center>
      <tr>
        <td>
      <select name=deptsel>
        <option value="value1">value1</option>
        <option value="value2">value2</option>
        <option value="value3">value3</option>
      </select>
    </td>
      </tr>
    </table>
    <input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();">
    <input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();">
    <input type="button" name=btnTest3 value="测 试3" onclick="funcTest();">
    </form>
      

  4.   

    opener.document.all.form1.deptsel.options[toLength]=new Option('hello','11111');
    就没问题,form1是你表单的name,deptsel是你select的name
      

  5.   

    很感谢铁鹰,但是我需要的是在子页面中得到的值(比如是一个select中所选option的值)去赋值给父页面,而不是跳回调父页面中的function
      

  6.   

    因为权限问题,只能用length++再赋值的方法,看例子
    <script>
    function mynew()
    {
    mynew=window.open('sub.htm','newwindow','');
    }
    function add()
    {
    form1.kk.add(new Option("text","value"),1);
    //add
    /*tmp="s123";
    form1.kk.options[0] = new Option(tmp,tmp);
    //change
    */
    }
    </script>
    <body onload=mynew()>
    <form name=form1>
    <input type=button value=change&add onclick="add()">
    <select name=kk>
    <option value=1>1
    <option value=12>12
    <option value=13>13
    </select>
    </form>sub.htm
    <form name=myform>
    <select name=myselect>
    <option value=s1>s1
    <option value=s12>s12
    <option value=s13>s13
    </select>
    <input type="button" name="but1" value="change&addopener" onclick=passBack()>
    </form>
    <script>
    function passBack() {
    if(document.myform.myselect.options.length!=0){
    tmp=document.myform.myselect.options[document.myform.myselect.selectedIndex].text;
             }//add
    //opener.document.form1.kk.add(new Option("text","value"),1);//服务器错
    opener.document.forms[0].kk.length++;
    opener.document.forms[0].kk.options[opener.document.forms[0].kk.length-1].text =tmp;
    opener.document.forms[0].kk.options[opener.document.forms[0].kk.length-1].value =tmp;/*
    //change
    opener.document.forms[0].kk.options[0] = new Option(tmp,tmp);//服务器错
    opener.document.forms[0].kk.options[0].text =tmp;
    opener.document.forms[0].kk.options[0].value =tmp;
    */
    }
    </script>
      

  7.   

    test2.html
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    </head>
    <body><button onclick=test()>test</button>
    <SCRIPT LANGUAGE="JavaScript">
    function test()
    {
      var options=window.opener.form1.deptsel.options;
      window.opener.btnTest_onclick(options[0].value+"mytest",options[1].value+"mytest",2);
    }
    </SCRIPT>
    </body>
    </html>
    //**************************************************************
    <script language=javascript>
      function btnTest_onclick(var1,var2,position1){
        form1.deptsel.options[position1]=new Option(var1,var2);
      }  function btnTest2_onclick(){
        window.open("test2.html");
      }
    </script>
    <form name=form1>
    <table border=1 align=center>
      <tr>
        <td>
      <select name=deptsel>
        <option value="value1">value1</option>
        <option value="value2">value2</option>
        <option value="value3">value3</option>
      </select>
    </td>
      </tr>
    </table>
    <!--<input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();">-->
    <input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();">
    </form>