<div id=divid>123</div>
< button onclick="usr()">Click</button>
< script>
function usr()
{
if(divid.style.visibility=='hidden')
{divid.style.visibility='visible';}
else
{divid.style.visibility='hidden';}
}
< /script>
或者
<div id=divid>123</div>
< button onclick="usr()">Click</button>
< script>
function usr()
{
if(divid.style.display=='')
{divid.style.display='none';}
else
{divid.style.display='';}
}
< /script>
//注意:display 与visibility 有区别!!
区别在于display 若不显示,则也不占地方,而visibility 若不显示,但占地方,