我正在尝试在输入数字时创建一个页面,然后在一个单独的页面上显示该数字的乘法,包括10.我可以使用document.write在新页面上显示该表格但没有格式化,仍然使用与第一个相同的URL。到目前为止,我已经尝试过:
window.location.href location.href 返回
原始页面:Assignment2_Input.html
结果页面:Assignment2_Outpul.html
脚本:Assignment2Script.js
任何帮助将不胜感激!
原始页面:
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Input</title>
<link href="Assignment2InputStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<div id="title">
<h2>Assignment 2</h2>
<h1>Multiplication Table</h1>
<form method="post"><label id="NumberLabel">Please Enter Number: </label><input id="Number" type="text" size="25"></form>
<br/>
<input id="submitButton" type="submit" value="Calculate" >
<p></p>
</div>
</div>
<br/>
<br/>
<script src="Assignment2_Script.js" type="text/javascript"></script>
</body>
</html>
结果页:(这是我在此网址上的格式)
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Input</title>
<link href="Assignment2InputStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<div id="title">
<h2>Assignment 2</h2>
<h1>Multiplication Table</h1>
<form method="post"><label id="NumberLabel">Please Enter Number: </label><input id="Number" type="text" size="25"></form>
<br/>
<input id="submitButton" type="submit" value="Calculate" >
<p></p>
</div>
</div>
<br/>
<br/>
<script src="Assignment2_Script.js" type="text/javascript"></script>
</body>
</html>
使用Javascript:
function calculate() {
num = document.getElementById("Number").value;
document.write('<body background-color="aqua">');
document.write('<table border="1" cellspacing="0">');
for(i=1;i<=10;i++) {
document.write("<tr><td>" + num + " x " + i + " = " + num*i + "</td></tr>");
}
document.write("</table>");
}
我现在已经在Chrome中使用了代码(仍然无法在Firefox中运行)
然而,当它切换到新页面时,它会将表闪烁一秒钟,然后它就会消失。有什么想法吗?