所以我正在做一個非常基本的事情。我寫了這個代碼。我無法從中得出結果。我不確定我做錯了什麼。因爲我在學習。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