需要三张不同的图片,默认背景图片为img1,鼠标放在控件上方背景图片为img2,鼠标离开背景图片恢复为img1,鼠标点击控件背景图片为img3.
主要应用于导航栏监听鼠标的位置和状态。
<div>
<buttonid="imgTab"οnmοuseοver="over(this)"οnmοuseοut="out(this)"οnmοusedοwn="down(this)"style="background-image:url(/image/img1.jpg)">
</button>
</div>
function over(x){
x.style.backgroundImage = "url(/image/img2.jpg)";
}
function out(x){
x.style.backgroundImage = "url(/image/img1.jpg)";
}
function down(x){
x.style.backgroundImage = "url(/image/img3.jpg)";
}