我一直在尝试使用javascript并且它可以工作,但突然停止工作,即js函数没有被调用。我已将.js和html文件放在桌面上,但仍无效。
错误:
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>
答案 0 :(得分:0)
试试这个.............
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';
}
}
function funcDate() {
document.getElementById("img1").alt = 'date add';
}
<!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 type="text/javascript" src="script1.js"></script>
</body>
</html>