<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#s1{
background-color:red;
width:300px;
height:300px;
}
#s2{
background-color:green;
width:300px;
height:300px;
}
</style>
</head>
<body>
<div id="s1" onClick="hg();"></div>
</body>
<script>
function hg(){
var div=document.getElementById('s1');
if (div.style.backgroundColor.indexOf("red")>=0)
{
div.id="s2";
}else{
div.id="s1";
}
}
</script>
</html>