【发布时间】:2015-07-31 19:51:12
【问题描述】:
HTML5 的新手,如果这是一个简单的解决方法,很抱歉 :)
我有这个 HTML 文件,它接受 4 个用户输入(整数)并将它们乘以 4 个其他变量,然后将新变量相加并将其输出到 HTML 中
via document.getElementById("out").innerHTML 当我在 chrome 中运行 HTML 时,它什么都不做,我不知道为什么,Adobe Dreamweaver 根本没有标记任何错误,它在浏览器中运行良好据我所知。 如果您确实修复了它,请尝试解释您在做什么以及它为什么起作用,并尝试保持我的代码保持其形式,以便我仍然可以理解它(希望这是有道理的?)
这是我的完整代码-
<!doctype html>
<html>
<body>
<h1><font face="arial">How much space do you need?</font></h1>
<h2><font face="arial">Number of Files: </font></h2>
<form id="filenum">
<font face="arial"> Documents: <input type="int" name="doc" value="0"><br></font>
<font face="arial"> Photos: <input type="int" name="photo" value="0"><br></font>
<font face="arial"> Music: <input type="int" name="music" value="0"><br> </font>
<font face="arial"> Films: <input type="int" name="film" value="0"><br></font>
</form>
<button onclick="outputsize()">Calculate</button>
<script>
var doc,photo,music,film,ttb,tgb,tmb,tdoc,tphoto,tmusic,tfilm,files,sdoc,sphoto,smusic,sfilm;
function outputsize() {
sdoc=0.1
sphoto=8
smusic=5
sfilm=1400
files=document.getElementById("filenum");
doc=x.elements["doc"].value;
photo=x.elements["photo"].value;
music=x.elements["music"].value;
film=x.elements["film"].value;
tdoc=doc*sdoc;
tphoto=photo*sphoto;
tmusic=music*smusic;
tfilm=film*sfilm;
tmb=tdoc + tphoto + tmusic + tfilm;
tgb=tmb/1000;
ttb=tgb/1000;
document.getElementById("out").innerHTML="You need a, "+tmb+"MB or bigger hard drive.<br>";
document.getElementById("out").innerHTML+="Or...<br>";
document.getElementById("out").innerHTML+="You need a, "+tgb+"GB or bigger hard drive.<br>";
document.getElementById("out").innerHTML+="Or...<br>";
document.getElementById("out").innerHTML+="You need a, "+ttb+"TB or bigger hard drive.<br>";
}
</script>
<p id="out"><font face="arial">We calculated:</font></p>
</body>
</html>
再次,对不起,如果这是一个愚蠢的问题(如果存在这样的事情),但我已经解决了几个小时并且无法解决它:(
【问题讨论】:
-
你曾经调用过那个函数吗/
-
检查您的控制台。看起来 x 没有定义。
标签: javascript html innerhtml getelementbyid