京东狗.jpg
<script>
//window.onload页面加载完毕以后在执行此代码
window.onload = funciton (){
//需求:鼠标放到img上,修改路径(src的值)
//步骤:
//1.获取事件源
//2.绑定事件
//3.书写事件驱动程序
//1.获取事件源
var img = document.getElementById("box");
//2.绑定事件(悬停鼠标:鼠标进入到事件源中,立即出发事件)
img.onmouseover = funciton(){
img.src = "image/jd2.png";
}
//1.获取事件源
var img = docuemnt.getElementById("box");
//2.绑定事件(悬停事件:鼠标进入到事件源中立即出发事件)
img.onmouseout = function(){
this.src = "image/jd1.png";
}
//获取事件源( 元素可以不获取直接使用id的值)
var img = document.getElementById(“box”);
//调用函数
img.onmouseover = fn1;
img.onmouseover = fn2;
//定义函数
function fn1 (){
img.src = "image/jd2.png";
}
function fn2(){
img.src = "image/jd1.png";
}
</script>
<body>
<img id ="box" src="image/jd1.png" style = "cursor:pointer;border:1px solid #ccc;"
</body>
网友评论