<html>
<head>
<title>Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://cloud.xing-xing.com/jquery.js"></script>
<style>
</style>
</head>
<body>
<img src="imges/404.png" id="img"/>
</body>
<script>
$(function(){
$('#img').click(function(){
if($(this).attr('checked')){
$(this).attr({'src': 'imges/404.png', 'checked': false});
}else{
$(this).attr({'src': 'imges/405.png', 'checked': true});
}
});
});
</script>
</html>
<head>
<title>Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://cloud.xing-xing.com/jquery.js"></script>
<style>
</style>
</head>
<body>
<img src="imges/404.png" id="img"/>
</body>
<script>
$(function(){
$('#img').click(function(){
if($(this).attr('checked')){
$(this).attr({'src': 'imges/404.png', 'checked': false});
}else{
$(this).attr({'src': 'imges/405.png', 'checked': true});
}
});
});
</script>
</html>
例如:
.normal{
background :11111.jpg
}.active{
background : 2222.jpg
}
(实际中更多的是多张图拼在一张大图上,css spirit定位)
点击的时候只需要切换不同的class即可。
<style>
div{
width:74px;
height:74px;
background:url(http://img.bbs.csdn.net/upload/201502/12/1423724129_595014.jpg) -35 -23px;
margin:10px;
}
.aa{
background:url(http://img.bbs.csdn.net/upload/201502/12/1423724152_641124.jpg) -28px -23px;
}
</style>
<div></div>
<div></div>
<script>
$('div').click(function(){$('div').removeClass('aa');$(this).addClass('aa')})
</script>