我正在尝试从 3 个文本字段中获取数据,将它们相乘并将值放在另一个文本字段中。
<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>
它不会提醒结果,所以我认为它停留在结果声明中。
我究竟做错了什么?
谢谢。