<script type="text/javascript">
var arr = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg"]
function pf(t) {
t.src = arr[Math.floor(Math.random()*arr.length)]
}
script>
<div class="gyyy"><img src="关于医院.jpg">
<span>关于医院</span>
</div>
$(function(){
var imgs=document.getElementsByName("img")
$(".gyyy").click(function(){
imgs.src="新图片的路径";
$(".gyyy>span").css("color","blue")
})
})
使用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
}