我一直在嘗試我的手在JavaScript上,它的工作原理,但突然停止工作,即js函數沒有被調用。我在桌面上放置了.js和html文件,但仍然無法正常工作。未捕獲ReferenceError:函數未定義錯誤,爲什麼?
錯誤:
Uncaught ReferenceError: funcLoadImage is not defined
at HTMLButtonElement.onclick
這個錯誤可能是任何功能我打電話。
JS:
function funcLoadImage() {
document.getElementById("img1").src = "https://upload.wikimedia.org/wikipedia/commons/3/36/Hopetoun_falls.jpg"
}
function funcMath(type, data) {
if (type == 1) {
document.getElementById("img1").alt = 'Type 1'
}
if (type == 2) {
document.getElementById("img1").alt = 'Type 2'
}
}
funtion funcDate() {
document.getElementById("img1").alt = 'date add'
}
HTML代碼:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img id="img1" src="" alt="No image loaded" width="50%" height="50%"/>
<button id="btn1" width="20%" height="20%" onclick='funcLoadImage()'>Load Image</button>
<button id="btn2" width="20%" height="20%" onmouseover="this.style.width='60%'" onmouseout="this.style.width='20%'">Write Doc</button>
<button id="btn3" width="20%" height="20%" onclick='funcMath(1,4)'>Calculate</button>
<button id="btn4" width="20%" height="20%" onclick='this.innerHTML=Date()'>Display Date</button>
<p>
</p>
<script src="script1.js"></script>
</body>
</html>
如果這是你的實際代碼,那麼你哈哈在這裏有一個錯誤'funtion funcDate',導致語法錯誤,所以'script1.js'的全部內容都沒有被評估,因爲那個語法錯誤。 –
謝謝先生。把它放在答案框中,我會標記爲答案 – Covert