因为你的hw() 和 hwwh()这两个函数不是写在打开的窗口里的,当然无法调用~~

解决方案 »

  1.   

    把你的js函数写在一个js.js 文件里:
    function wh(){
    var xm;
    var mm;
    xm=newWindow.document.form1.text1.value;
    mm=newWindow.document.form1.text2.value;
    if(xm==""){alert("请填写用户名")}
     else if(mm==""){alert("请输入密码")}
       else if(xm!="a"||mm!="0"){alert("您输入的用户名或密码错误,请重新输入")}
    }function hwwh(){
    newWindow.document.form1.text1.value="";
    newWindow.document.form1.text2.value="";}然后:
     <html>
    <head>
    <script language="JavaScript">
    <!--function hw(){
    var newWindow=window.open('','','width=230,height=148,left=300,top=200,ScrollBar=no,menubar=0,toolbar=0');
    newWindow.document.write("<html>");
    newWindow.document.write("<head>");newWindow.document.write("<script language='javascript' src='js.js'>");  // 在这里加两行代码
    newWindow.document.write("</script>");newWindow.document.write("<title>用户登陆</title>");
    newWindow.document.write("</head>");
    newWindow.document.write("<body background='hw 1.gif'>");
    newWindow.document.write("<br>");
    newWindow.document.write("<form name='form1'>");
    newWindow.document.write("&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp");
    newWindow.document.write("<input type='text' name='text1' size=10>");
    newWindow.document.write("&nbsp &nbsp &nbsp &nbsp &nbsp  &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp");
    newWindow.document.write("<input type='text' name='text2' size=10> ");
    newWindow.document.write("</form>");
    newWindow.document.write("&nbsp &nbsp &nbsp");newWindow.document.write("<img src='hw 3.gif' onclick='wh()'>");
    newWindow.document.write("&nbsp &nbsp  &nbsp");
    newWindow.document.write("<img src='hw 2.gif' onclick='hwwh()'>");
    newWindow.document.write("&nbsp  &nbsp &nbsp");
    newWindow.document.write("<img src='hw4.gif' onclick='self.close()'>");
    newWindow.document.write("</body>");
    newWindow.document.write("</html>");
    newWindow.document.form1.text1.focus();
    newWindow.document.close();}//-->
    </script>
    </head>
    <body onload="hw()"></body>
    </html>
      

  2.   

    子窗口不能执行父窗口的函数
    将函数写到js中调用或直接使用document.write写入调用
      

  3.   

    这是修改后的正确代码:
    ——————————————————————
    <html>
    <head>
    <script language="JavaScript">
    <!--function hw(){
    var newWindow=window.open('','','width=530,height=548,left=300,top=200,ScrollBar=no,menubar=0,toolbar=0');
    newWindow.document.write("<html>");
    newWindow.document.write("<head>");
    newWindow.document.write("<title>用户登陆</title>");
    newWindow.document.write("</head>");
    newWindow.document.write("<body background='hw 1.gif'>");
    newWindow.document.write("<br>");
    newWindow.document.write("<form name='form1'>");
    newWindow.document.write("&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp");
    newWindow.document.write("<input type='text' name='text1' size=10>");
    newWindow.document.write("&nbsp &nbsp &nbsp &nbsp &nbsp  &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp");
    newWindow.document.write("<input type='text' name='text2' size=10> ");
    newWindow.document.write("</form>");
    newWindow.document.write("&nbsp &nbsp &nbsp");newWindow.document.write("<img src='hw3.gif' onclick='wh()'>HW3.GIF");
    newWindow.document.write("&nbsp &nbsp  &nbsp");
    newWindow.document.write("<img src='hw2.gif' onclick='hwwh()'>HW2.GIF");
    newWindow.document.write("&nbsp  &nbsp &nbsp");
    newWindow.document.write("<img src='hw4.gif' onclick='self.close()'>HW4.GIF");
    newWindow.document.write("<script>");
    newWindow.document.write("function wh(){var xm;var mm;xm=document.form1.text1.value;mm=document.form1.text2.value;if(xm==''){alert('请填写用户名')} else if(mm==''){alert('请输入密码')}else if(xm!='a'||mm!='0'){alert('您输入的用户名或密码错误,请重新输入')}}function hwwh(){document.form1.text1.value='';document.form1.text2.value='';}");
    newWindow.document.write("</script>");
    newWindow.document.write("</body>");
    newWindow.document.write("</html>");
    newWindow.document.form1.text1.focus();
    newWindow.document.close();}//-->
    </script>
    </head>
    <body onload="hw()"></body>
    </html>