加上这句
window.opener.document.getElementById('username').value=printhtml;
就OK了

解决方案 »

  1.   

    <script language="javascript">  
    function to_to(s){ 
    var printhtml = "";  
    printhtml += "  <form name='f' action='test.php' method='POST'>";  
    printhtml += "  <input type='text' id='username' name='username' value='" + s + "'>";  
    printhtml += "  <input type='submit'>";  
    printhtml += "  </form>";  
    opener.document.getElementById("msg").innerHTML = printhtml;
    }
    </script>
    <a href=# onclick="to_to('要输入的文字')">check</a>
      

  2.   

    那同时在printhtml中的username文本框输入文字,如何解决呀?
      

  3.   


    <script language="javascript">  
    function to_to(){  var printhtml = "  <html>body>";  
    printhtml += "  <form name='f' action='test.php' method='POST'>";  
    printhtml += "  <input type='text' id='username' name='username'>";  
    printhtml += "  <input type='submit'>";  
    printhtml += "  </form>";  
    printhtml += "  </body>  </html>";  
    window.opener.document.getElementById('msg').innerText=printhtml; window.opener.document.getElementById('username').value="输入名称";
    }  
    </script>  
      

  4.   

    window.opener.document.getElementById('msg').innerText=printhtml;  
    换成window.opener.document.getElementById("msg").innerHTML = printhtml; 带有html的