$(座位的selector).click(function(){
var attr_class=$(this).attr('class')
if(attr_class=='灰'){
return false
}
if(attr_class=='红'){
$(this).removeClass('红')
$(this).addClass('蓝')
return
}
if(attr_class=='蓝'){
$(座位的selector).each(function(){
$(this).removeClass('红')
})
$(this).removeClass('蓝')
$(this).addClass('红')
return
}
})
<!DOCTYPE HTML><html>
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
<script>
var row=2,col=11,size=20,gap=5
window.onload=function(){
var wrap=document.createElement("div")
wrap.style.margin="0 auto"
wrap.style.width=(size+gap)*col+"px"
for(var i=0i<rowi++){
var rows=document.createElement("div")
rows.style.float="left"
rows.style.marginBottom=gap+"px"
for(var j=0j<colj++){
var div=document.createElement("img")
div.src="a.png"
div.style.width=size+"px"
div.style.height=size+"px"
div.style.float="left"
div.style.marginLeft=gap+"px"
div.onclick=function(){
!this.abc?this.src="b.png":this.src="a.png"
this.abc=!this.abc
}
rows.appendChild(div)
}
wrap.appendChild(rows)
}
document.body.appendChild(wrap)
}
</script>
</head>
<body>
</body>
</html>