代码如下:
<Form name="form1">
用户名:<input type="text" name="name1">
密码: <input type="password" name="mima">
<button name="button1" onclick="print()" value="输出">
<\form>function print()
{
document.write("用户名:"+document.form1.name1.value+"<br>");
document.write("密 码:"+document.form1.mima.value+"<br>");
}如果只用一个document.write不报错,使用两个document.write出错。
<Form name="form1">
用户名:<input type="text" name="name1">
密码: <input type="password" name="mima">
<button name="button1" onclick="print()" value="输出">
<\form>function print()
{
document.write("用户名:"+document.form1.name1.value+"<br>");
document.write("密 码:"+document.form1.mima.value+"<br>");
}如果只用一个document.write不报错,使用两个document.write出错。
你一起输出就可以了! <Form name="form1">
用户名:<input type="text" name="name1"/>
密码: <input type="password" name="mima"/>
<input type="button" name="button1" onclick="print()" value="show"/>
</form>
<script>
function print()
{
document.write("用户名:"+document.form1.name1.value+"<br>"+"密 码:"+document.form1.mima.value+"<br>");
// document.write("密 码:"+document.form1.mima.value+"<br>");
}
</script>
{
var n=document.form1.name1.value;
var p=document.form1.mima.value;
document.write("用户名:"+n+"<br>");
document.write("密 码:"+p+"<br>");
}
IE浏览器的document.write转向了一个新的页面,所以使用完doucument.write后,document.form1.mima元素根本获取不了,所以document.form1.mima.value是错误的。
火狐浏览器则不会出现lz上述问题。
两种方法:
1换一种浏览器
2在doucment.wirte使用时,提前把页面的值取出来。
如下:
<html>
<head>
<title> html test
</title>
<script type='text/javascript'>
function print1()
{
var a=document.form1.mima.value;
document.write("用户名:"+document.form1.name1.value+"<br>");
//document.write("密 码:"+document.form1.mima.value+"<br>");
document.write("密 码:"+a+"<br>");
}
</script>
</head>
<body>
<Form name="form1">
用户名:<input type="text" name="name1">
密码: <input type="password" name="mima">
<button name="button1" onclick="print1()" >bb</button>
</form>
</html>
</body>
</html>