作者Leavesb (搞笑藝鵝)
看板Ajax
標題[問題] 想請問一個 JavaScript 讀入 .js 檔的問題
時間Wed Aug 26 17:27:28 2009
以下是我的程式
主程式
<html>
<head>
<title>Sample</title>
<script
type = "text/javascript" src = "common.js"> </script>
</head>
<body>
<form>
<input type = "text" name = "num1" value = ""> <br>
<input type = "text" name = "num2" value = ""> <br>
<input type = "button" value = "兩個值的相乘"
onClick = "alert(multi(this.form.num1.value, this.form.num2.value))"> <br>
</form>
</body>
</html>
外部檔案 (common.js)
function multi (n1, n2)
{
result = parseFloat(n1) * parseFloat(n2);
return result;
}
──────────────────────────────────────
這是照書上打的 輸入兩值 然後用 ALERT 跳出結果
但是用火狐跑的時候 錯誤主控台會出現 「illegal character」 的錯誤
若把 黃色處的 type 改成 language 後 可以去掉上面的錯誤
但是點按鈕後後 錯誤主控台會說 「multi is not defined」 也沒有 ALERT 跳出
請問版友們
這個程式出了什麼問題嗎
如果可以的話麻煩抽空回覆我 感激不盡 :)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.241.114
1F:→ Leavesb:兩個檔案在同一路徑下 08/26 17:50
※ 編輯: Leavesb 來自: 140.113.241.114 (08/26 19:44)
2F:推 tomin:code沒錯 common.js要(用記事本)存成utf-8編碼 08/26 20:46
3F:→ Leavesb:相當感謝!!! n(_ _)n 08/26 20:51