怎么用CSS或者JS实现鼠标点击变换背景图片?

html-css021

怎么用CSS或者JS实现鼠标点击变换背景图片?,第1张

使用jquery的toggle方法进行图片切换\x0d\x0a$(function(){\x0d\x0a$("#h1").toggle(function(){\x0d\x0a$("#h1").css("background-image","路径('./20110528073501b54e6.jpg')")\x0d\x0a},function(){\x0d\x0a$("#h1").css("background-image","路径('./2011060708410874041.jpg')")\x0d\x0a})\x0d\x0a}) \x0d\x0a\x0d\x0a\x0d\x0a \x0d\x0aCSS\x0d\x0a.hh1{\x0d\x0abackground: url("./2011060708410874041.jpg")\x0d\x0awidth: 120px\x0d\x0aheight: 90px\x0d\x0a}

使用jquery的toggle方法进行图片切换:

$(function(){

$("#h1").toggle(function(){

$("#h1").css("background-image","路径('./20110528073501b54e6.jpg')")

},function(){

$("#h1").css("background-image","路径('./2011060708410874041.jpg')")

})

})

<input type="button" value="huan" id="h1" class="hh1" />

CSS

.hh1{

background: url("./2011060708410874041.jpg")

width: 120px

height: 90px

}