从html文本框获取输入,然后将其放入Javascript变量不起作用

时间:2015-10-23 04:36:28

标签: javascript html

这是我的代码。当我点击计算按钮时,它只显示数字35.我错了,我该如何解决?

<!doctype html>
<html>
<head>
<title>JS Practise 2</title>
</head>

<body>
<h1> Problem 1.1 </h1>
<script language="javascript">
var topsoil_amount = 1;
function calculate() {
	var topsoil_amount = document.getElementById(Input);
	var topsoil_cost = 15;
	var cost = (topsoil_amount * topsoil_cost) + 35;	
	alert(cost);
}

</script>
<br>
<input type="text" name="Input" size="16" id="Input">
<input type="button" value="Calculate" onClick="calculate()">
</body>
</html>

1 个答案:

答案 0 :(得分:1)

[Test] public void ExplodeRange() { var output = Range.Explode(5, 9); Assert.AreEqual(5, output.Count); Assert.AreEqual(5, output[0]); Assert.AreEqual(6, output[1]); Assert.AreEqual(7, output[2]); Assert.AreEqual(8, output[3]); Assert.AreEqual(9, output[4]); } [Test] public void ExplodeSingle() { var output = Range.Explode(1, 1); Assert.AreEqual(1, output.Count); Assert.AreEqual(1, output[0]); } [Test] public void InterpretSimple() { var output = Range.Interpret("50"); Assert.AreEqual(1, output.Count); Assert.AreEqual(50, output[0]); } [Test] public void InterpretComplex() { var output = Range.Interpret("1,5-9,14,16,17,20-24"); Assert.AreEqual(14, output.Count); Assert.AreEqual(1, output[0]); Assert.AreEqual(5, output[1]); Assert.AreEqual(6, output[2]); Assert.AreEqual(7, output[3]); Assert.AreEqual(8, output[4]); Assert.AreEqual(9, output[5]); Assert.AreEqual(14, output[6]); Assert.AreEqual(16, output[7]); Assert.AreEqual(17, output[8]); Assert.AreEqual(20, output[9]); Assert.AreEqual(21, output[10]); Assert.AreEqual(22, output[11]); Assert.AreEqual(23, output[12]); Assert.AreEqual(24, output[13]); } [ExpectedException(typeof (FormatException))] [Test] public void InterpretBad() { Range.Interpret("powdered toast man"); } 是一个DOM元素,而不是数字。您需要引用该值。 Secons问题是你需要在id周围引用。

topsoil_amount