html中实现数据的显示和隐藏

来自:互联网
时间:2019-08-09
阅读:
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>demo</title>
<script>
var obj = document.getElementById("div_id");
function hideOrShowEvent(){
var obj= document.getElementById("div_id");
if(obj.style.display=="block"){ //如果是显示则隐藏
obj.style.display="none";
}else{ //如果是隐藏则显示
obj.style.display="block";
}
}
</script>
</head>
<body>
<div id="div_id" style="border:1px solid red;display:block;" > 这里是内容 </div>
<button type="button" onclick=hideOrShowEvent()> 点击隐藏或显示 </button>
</body>
</html>
返回顶部
顶部