日期:2014-05-16 浏览次数:20527 次
$('img').click(function() {
$(this).attr('src', $(this).attr('src')=='钩号图片url'?'叉号图片url':'钩号图片url');
});
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<span>勾</span>
<span class="err">叉</span>
<span>勾</span>
<span class="err">叉</span>
<span>勾</span>
<span class="err">叉</span>
<script>
//默认class为空时background是勾 class为err 是叉
window.onload = function(){
var span = document.getElementsByTagName('span');
for(var i=0;i<span.length;i++){
span[i].onclick = function(){
if(this.className == ''){
this.className = 'err';
this.innerHTML = '叉';
}else{
this.className = '';
this.innerHTML = '勾';
}
}
}
}
</script>
</body>
</html>