<html>
<head>
<title>空白</title>
</head>
<script language="javascript">
function XS(){
document.write("用户名:"+ document.form1.username.value);
document.write("密码:"+ document.form1.password.value);
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<label>用户名:
<input name="username" type="text" id="username" />
</label>
<p>
<label>密 码:
<input name="password" type="text" id="password" />
</label>
</p>
<p>
<input type="button" name="Submit" value="显示" onclick="XS()" />
<input type="reset" name="Submit2" value="清空" />
</p>
</form>
</body>
</html>
运行后只输出第一个Document.write("用户名:"+ document.form1.username.value);的内容;
而一下代码就行:
<html>
<head>
<title>空白</title>
</head>
<script language="javascript">
function XS(){
var mywin=open();
mywin.document.write("用户名:"+ document.form1.username.value);
mywin.document.write("<br>");
mywin.document.write("密码:"+ document.form1.password.value);
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
<label>用户名:
<input name="username" type="text" id="username" />
</label>
<p>
<label>密 码:
<input name="password" type="text" id="password" />
</label>
</p>
<p>
<input type="button" name="Submit" value="显示" onclick="XS()" />
<input type="reset" name="Submit2" value="清空" />
</p>
</form>
</body>
</html>
运行后 两个mywin.document.write(“xxxx“)内容都能输出。
请同学们解释一下原因,谢谢。
WeberYang
相关分类