我正在为班级做作业,我觉得我可能只是有一些简单的语法错误。我试图在JS中创建的表格根本不显示在名为result的HTML div中。JavaScript表格显示不正确
https://imgur.com/a/fawJT(这是与分配方向上的输出例子)
http://imgur.com/a/Khh0h(我的代码是我们在按下计算所有投入将消失,DIV结果功课接口RAN空缺)
JS
function link_events() {
document.getElementById("calculate").onclick = calculate;
}
function calculate() {
var years = document.getElementById('years');
var population = parseInt(document.getElementById('population').value);
var rate = parseInt(documet.getElementById('rate').value);
var table = '' +
'<table>' +
'<tr>' +
'<th><strong>Year</strong></th>' +
'<th><strong>Population</strong></th>' +
'<th><strong>Change</strong></th>' +
'</tr>' +
'';
var currentYear = 2017;
for (var i = currentYear; i < (currentYear+years); i++) {
var change = (population*rate)/100;
population += change;
table += '' +
'<tr>' +
'<td>' + i + '</td>' +
'<td>' + population.toFixed() + '</td>' +
'<td>' + change.toFixed() + '</td>' +
'</tr>' +
'';
}
table += '' +
'</table>' +
'';
document.getElementById('result').innerHTML = table;
}
HTML
<!doctype html>
<META HTTPEQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<meta httpequiv="expires" content="0" />
<html lang="en">
<head>
<title> hw8 </title>
<link rel="stylesheet" href="hw8.css">
<script src="hw8.js"></script>
</head>
<body>
<form name="inputform">
<div id="input">
<h2> Population Growth </h2>
Years to forecast: <input type="text" value="<? print $_POST['years']; ?>" name="years"> <br/> <br/>
Current Population: <input type="text" value="<? print $_POST['population']; ?>" name="population"> <br/> <br/>
Growth Rate: <input type="text" value="<? print $_POST['rate']; ?>" name="rate"> <br/> <br/>
<div id="button"> <input type="submit" value="Calculate" id="calculate"> </div>
</div>
</form>
<div id="result"> </div>
</body>
</html>
你能告诉我们结果你有没有正当的说“没有正确显示”或提供一个笨蛋? – Sorikairo
它根本没有显示表格 –
我会尝试上传截图 –