我想製作一個表格,用戶可以在其中填充某些單元格的值,然後單擊「提交」以顯示計算結果。我的目錄中有jquery-2.0.3.min.js和script.js。這是我的HTML代碼:本地添加javascript到xampp做數學/公式
<!DOCTYPE html>
<html>
<head>
<title>Inteligence Decision Support System</title>
<script src='localhost/idss/jquery-2.0.3.min.js'></script>
<script type="text/javascript" src='localhost/idss/script.js' charset="utf-8"></script>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Cost</th>
<th>x20</th>
<th>x25</th>
</tr>
<tr>
<td>someName</td>
<td><input name="Cost" type="text" value="0"></td>
<td><input name="a20" type="text" value=""></td>
<td><input name="a25" type="text" value=""></td>
</tr>
</table>
<input type="button" onclick="Zcount()" value="Submit" >
</body>
</html>
而這裏的script.js文件
<script type="text/javascript">
function Zcount(){
var cost, a20, a25;
a20 = document.getElementById("a20").value;
a25 = document.getElementById("a25").value;
cost = (2*parseInt(a20))+(3*parseInt(a25));
document.getElementById("Cost").value=cost;
}
</script>
但是當我充滿A20和A25,並點擊提交按鈕,什麼都沒有發生。結果保持爲零。我哪裏做錯了?
這是什麼都與XAMPP辦? – veelen
我想弄清楚我調用腳本文件的方式是否是錯誤的,或者我應該把它放在xampp文件夾中的其他地方。無論如何,我只是試圖把腳本放在我的html代碼中,但那也不管用。 – user3096079