我試圖從3個文本字段獲取數據,將它們相乘並將該值放入另一個文本字段中。Javascript - 更改文本字段的值
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type='text/javascript'>
function run()
{
var eq = document.getElementById("Eq");
var m = document.getElementById("m1");
var c = document.getElementById("c");
var dT = document.getElementById("dT");
var ek = document.getElementById("Ek");
var v = document.getElementById("v");
if(eq.value.length == 0)
{
var result = parseFloat(m.value) * parseFloat(c.value) * parseFloat(dT.value);
alert(result);
eq.value = result.toString();
}
if(c.value.length == 0)
{
c.value = eq.value/(m.value * dT.value);
}
}
function m1change()
{
var m1 = document.getElementById("m1");
var m2 = document.getElementById("m2");
m2.value = m1.value;
}
function m2change()
{
var m1 = document.getElementById("m1");
var m2 = document.getElementById("m2");
m1.value = m2.value;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - ברוכים הבאים</title>
</head>
<body>
<form action="">
<h1>Eq = m * c * ΔT</h1>
<input type="number" max="2147483648" id="Eq" maxlength="10" /> = <input type="number" max="10" class="m" id="m1" maxlength="10" onkeyup="m1change()" /> * <input type="number" max="2147483648" id="cHeat" maxlength="10" /> * <input type="number" max="2147483648" id="dT" maxlength="10" />
<h1>Ek = (m * v²)/2</h1>
<input type="number" max="2147483648" id="Ek" maxlength="10" /> = (<input type="number" max="10" class="m" id="m2" maxlength="10" onkeyup="m2change()" /> * <input type="number" max="2147483648" id="v" maxlength="10" /><font size="6.5">²</font> )/2
<h1>Eh = m * g * h</h1>
<input type="reset" /> <input type="button" onclick="run()" value="Calculate" />
<h6>by X</h6>
</form>
</body>
</html>
它不提示結果,所以我認爲它卡在結果的聲明。
我在做什麼錯?
謝謝。
錯誤控制檯窗口中的任何錯誤? – Dolly 2013-05-01 05:06:14
不是我可以看到的... – user2338361 2013-05-01 05:06:50
嘗試在第一行的函數體中提醒 – Dolly 2013-05-01 05:06:51