为什么点击‘hw 3.gif' 不调用‘wh()’?
为什么点击‘hw 2.gif' 不调用‘hwwh()’?
我想了好几天都没想通,请高手指教!!!!
1<html>
2<head>
3<script language="JavaScript">
4<!--
5
6function hw(){
7var newWindow=window.open('','','width=230,height=148,left=300,top=200,ScrollBar=no,menubar=0,toolbar=0');
8newWindow.document.write("<html>");
9newWindow.document.write("<head>");
10newWindow.document.write("<title>用户登陆</title>");
11newWindow.document.write("</head>");
12newWindow.document.write("<body background='hw 1.gif'>");
13newWindow.document.write("<br>");
14newWindow.document.write("<form name='form1'>");
15newWindow.document.write("                       ");
16newWindow.document.write("<input type='text' name='text1' size=10>");
17newWindow.document.write("                             ");
18newWindow.document.write("<input type='text' name='text2' size=10> ");
19newWindow.document.write("</form>");
20newWindow.document.write("     ");
21
22newWindow.document.write("<img src='hw 3.gif' onclick='wh()'>");
23newWindow.document.write("     ");
24newWindow.document.write("<img src='hw 2.gif' onclick='hwwh()'>");
25newWindow.document.write("     ");
26newWindow.document.write("<img src='hw4.gif' onclick='self.close()'>");
27newWindow.document.write("</body>");
28newWindow.document.write("</html>");
29newWindow.document.form1.text1.focus();
30newWindow.document.close();
31
32}
33
34function wh(){
35var xm;
36var mm;
37xm=newWindow.document.form1.text1.value;
38mm=newWindow.document.form1.text2.value;
39if(xm==""){alert("请填写用户名")}
40else if(mm==""){alert("请输入密码")}
41else if(xm!="a" ¦ ¦mm!="0"){alert("您输入的用户名或密码错误,请重新输入")}
42}
43
44function hwwh(){
45newWindow.document.form1.text1.value="";
46newWindow.document.form1.text2.value="";
47
48}
49//-->
50</script>
51</head>
52<body onload="hw()">
53</body>
54</html>
---------------------------------------------------------------
因为你的hw() 和 hwwh()这两个函数不是写在打开的窗口里的,当然无法调用~~
---------------------------------------------------------------
把你的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="";
}
然后:
1<html>
2<head>
3<script language="JavaScript">
4<!--
5
6function hw(){
7var newWindow=window.open('','','width=230,height=148,left=300,top=200,ScrollBar=no,menubar=0,toolbar=0');
8newWindow.document.write("<html>");
9newWindow.document.write("<head>");
10
11newWindow.document.write("<script language='javascript' src='js.js'>"); // 在这里加两行代码
12newWindow.document.write("</script>");
13
14newWindow.document.write("<title>用户登陆</title>");
15newWindow.document.write("</head>");
16newWindow.document.write("<body background="hw 1.gif">");
17newWindow.document.write("<br/>");
18newWindow.document.write("<form name="form1">");
19newWindow.document.write(" ");
20newWindow.document.write("<input name="text1" size="10" type="text"/>");
21newWindow.document.write(" ");
22newWindow.document.write("<input name="text2" size="10" type="text"/> ");
23newWindow.document.write("</form>");
24newWindow.document.write(" ");
25
26newWindow.document.write("<img onclick="wh()" src="hw 3.gif"/>");
27newWindow.document.write(" ");
28newWindow.document.write("<img onclick="hwwh()" src="hw 2.gif"/>");
29newWindow.document.write(" ");
30newWindow.document.write("<img onclick="self.close()" src="hw4.gif"/>");
31newWindow.document.write("</body>");
32newWindow.document.write("</html>
");
newWindow.document.form1.text1.focus();
newWindow.document.close();
}
//-->
1<body onload="hw()">
2</body>
---------------------------------------------------------------
子窗口不能执行父窗口的函数
将函数写到js中调用或直接使用document.write写入调用
---------------------------------------------------------------
这是修改后的正确代码:
——————————————————————
1<html>
2<head>
3<script language="JavaScript">
4<!--
5
6function hw(){
7var newWindow=window.open('','','width=530,height=548,left=300,top=200,ScrollBar=no,menubar=0,toolbar=0');
8newWindow.document.write("<html>");
9newWindow.document.write("<head>");
10newWindow.document.write("<title>用户登陆</title>");
11newWindow.document.write("</head>");
12newWindow.document.write("<body background='hw 1.gif'>");
13newWindow.document.write("<br>");
14newWindow.document.write("<form name='form1'>");
15newWindow.document.write("                       ");
16newWindow.document.write("<input type='text' name='text1' size=10>");
17newWindow.document.write("                             ");
18newWindow.document.write("<input type='text' name='text2' size=10> ");
19newWindow.document.write("</form>");
20newWindow.document.write("     ");
21
22newWindow.document.write("<img src='hw3.gif' onclick='wh()'>HW3.GIF");
23newWindow.document.write("     ");
24newWindow.document.write("<img src='hw2.gif' onclick='hwwh()'>HW2.GIF");
25newWindow.document.write("     ");
26newWindow.document.write("<img src='hw4.gif' onclick='self.close()'>HW4.GIF");
27newWindow.document.write("<script>");
28newWindow.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='';}");
29newWindow.document.write("</script>");
30newWindow.document.write("");
31newWindow.document.write("</head></html>
");
newWindow.document.form1.text1.focus();
newWindow.document.close();
}
//-->
1<body onload="hw()">
2</body>