js第一天 点击按钮显示与隐藏

时间:2023-03-08 20:25:46

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" >
window.onload=function(){
var weibo=document.getElementById('weibo');
var content=document.getElementById('content');
var box=document.getElementById('box');
var weibo1=document.getElementById('weibo1');

weibo.onclick=function(){

content.style.display="block";
weibo.style.backgroundColor="red";

}
weibo1.onclick=function(){

content.style.display="none";
weibo.style.backgroundColor="white";

}
}

</script>

<style>

#box{
width: 400px;height: 400px;
}
#weibo{
text-align: center;
}
#box>#content{
height: 150px;width: 100%;background-color: yellow; text-align: center;line-height: 50px;display: none;
}
</style>

</head>
<body>
<div id="box">
<input type="button" value="显示" id="weibo" />
<input type="button" value="隐藏" id="weibo1" />

<div id="content">
<div class="a"> 文本1</div>
<div class="b"> 文本2</div>
<div class="c"> 文本3</div>
</div>
</div>
</body>
</html>