<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<img id="kongxin" src="images/kongxin.png" alt="" />
<img id="shixin" src="images/shixin.png" alt="" />
</body>
<!-- 先隐藏实心 可以理解为 kongxin 是一个颜色 shixin 是一个颜色-->
<style type="text/css">
#shixin{
display:none;
}
</style>
<script type="text/javascript">
var kongxin = document.getElementById("kongxin");
var shixin = document.getElementById("shixin");
kongxin.onclick=function(){
this.style.display = 'none';
shixin.style.display = 'block';
}
</script>
</html>
追问点击是实心,再点击不能变回空心,这个怎么解决呢?谢谢
追答<script type="text/javascript">
var kongxin = document.getElementById("kongxin");
var shixin = document.getElementById("shixin");
//空心点击变实心
kongxin.onclick=function(){
this.style.display = 'none';
shixin.style.display = 'block';
}
//实心点击变空心
shixin.onclick=function(){
this.style.display = 'none';
kongxin.style.display = 'block';
}
</script>本回答被提问者采纳