<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JS学习</title>
<style>
div{
width: 300px;
height: 200px;
background-color: darkmagenta;
display: none;
}
</style>
</head>
<body>
<input type="button" value="隐藏" id="btn" />
<div id="dv"></div>
<script>
var btn1=document.getElementById("btn");
var dv1=document.getElementById("dv");
btn1.onclick=function(){
if(this.value=="隐藏"){
dv1.style.display="none";
this.value="显示";
}else if(this.value=="显示"){
dv1.style.display="block";
this.value="隐藏";
}
}</script>
</body>
</html>
目前是我没把它放在BADY内,现把它放在BADY里才能实现,怎样才能放在头部又能实现这个效果呢