JS实现点击显示与隐藏

来源:互联网 发布:star法则 程序员 编辑:程序博客网 时间:2024/06/05 15:31
<html><head><meta charset="utf-8"/><title>点击显示/隐藏</title><style type="text/css">#thediv{ width:200px; height:100px; line-height:100px; text-align:center; background-color:green;}</style><script type="text/javascript">function S_h(obj){if(obj.style.display=='block'){obj.style.display='none';}
 else
 {
  obj.style.display='block';
 }
}
</script></head>
window.onload = function(){
var olink = document.getElemetnById("link");
var td = document.getElemtnById("thediv");
olink.onclick = function(){
S_h(td);
return false;
}
}<body><a href="#" id="link">显示\隐藏切换</a><div id="thediv" style="display:block">显示/隐藏</div></body></html>

0 0
原创粉丝点击