当onmouseover和onmouseout时javascript会更改图像
我是一个初学者,我正在做作业,我有一个小问题。我的任务是当onmouseover打开时,image1应该更改为image2。当onmouseout打开时,应将image2更改为image1 Onmouseover工作,但onmouseout不工作! 这是我的密码:当onmouseover和onmouseout时javascript会更改图像,javascript,html,dom,Javascript,Html,Dom,我是一个初学者,我正在做作业,我有一个小问题。我的任务是当onmouseover打开时,image1应该更改为image2。当onmouseout打开时,应将image2更改为image1 Onmouseover工作,但onmouseout不工作! 这是我的密码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>DOM_4</title> </he
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DOM_4</title>
</head>
<body>
<img onmouseover = "changePic1()"onmouseout= "changePic2()" id="myImg" src="bakground.jpg" width="150" height="200">
<script>
function changePic1() {
document.getElementById("myImg").src = "screen.jpg";
}
function changePic22(){
document.getElementByID("myImg").src = "bakground.jpg";
}
</script>
</body>
</html>
多莫4
函数changePic1(){
document.getElementById(“myImg”).src=“screen.jpg”;
}
函数更改pic22(){
document.getElementByID(“myImg”).src=“bakground.jpg”;
}
为什么我的onmouseout不起作用?我知道有更好的编码方法,但我必须同时使用onmouseover和onmouseout。应该只有HTML和简单的javascript代码。(我的老师这样说)您的函数名
changePic22()
不正确,而且您还有语法错误document.getElementByID
将您的代码替换为此代码
function changePic1() {
document.getElementById("myImg").src = "screen.jpg";
}
function changePic2(){
document.getElementById("myImg").src = "bakground.jpg";
}
试试这个:
JS:
HTML:
<img onmouseover = "changePic1()" onmouseout= "changePic22()" id="myImg" src="" width="150" height="200">
bakground.jpg是否拼写正确?@ᔕᖺᘎᕊ 我知道这是不正确的。但是我刚刚有一个名为bakground.jpg的文件。没问题,只是想检查一下,因为这很容易出错:)哦!谢谢,我没有看到我有一个不正确的函数名!但是那个语法错误我找不到。。我犯了哪个语法错误?啊哈,我发现了!!谢谢它工作得很好。非常感谢。
<img onmouseover = "changePic1()" onmouseout= "changePic22()" id="myImg" src="" width="150" height="200">