所以我正在做一个非常基本的事情。我写了这个代码。我无法从中得出结果。我不确定我做错了什么。因为我在学习。HTML计算器
<head>
<script language="javascript" type="text/javascript">
function add(){
var input1=a;
var input2=b;
var result = a+b;
input1 = parseInt(document.getElementById("t1").value);
input2 = parseInt(document.getElementById("t2").value);
document.write("result");
}
</script>
<title>java</title>
</head>
<body>
<form name="f1">
<input type="text" id="t1" name="t1">
<input type="text" id="t2" name="t2">
<p>
<input type="button" id="add" value="add" onClick="function add();">
<input type="button" id="divide" value="divide" onClick="javascript:function divide();">
<input type="button" id="subtract" value="subtract" onClick="javascript:function subtract();">
<input type="button" id="multiply" value="multiply" onClick="javascript:function multiply();">
</p>
</form>
</body>
</html>
但它不会产生结果。
变量a和b不要选中此似乎没有定义编辑。我想你是用正确的方式来做这件事的...... 你想先得到'parseInt(..)'的值然后再加上'document.write(input1 + input2)' – charly 2013-03-19 06:38:37
不要'onClick = “function add();”'。做'onClick =“add()”'。 – 2013-03-19 06:38:49