作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试使用 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>
最佳答案
试试这个......
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>
关于javascript - 未捕获的 ReferenceError : functionis not defined error, 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42360195/
我一直在尝试使用 javascript,它可以工作,但突然停止工作,即 js 函数没有被调用。我已将 .js 和 html 文件放在桌面上,但仍然无法正常工作。 错误: Uncaught Refere
我是一名优秀的程序员,十分优秀!