资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

javascript显示和隐藏div的方法

这篇文章给大家分享的是有关javascript显示和隐藏div的方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

金湖ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

javascript显示隐藏div的方法:首先新建文件,并创建button按钮;然后创建隐藏的div,并给div设置隐藏的样式;最后为button按钮添加一个点击后隐藏事件。

javascript显示隐藏div的方法:

1、打开html开发软件,新建一个html文件。如图:

javascript显示和隐藏div的方法

2、在html文件上创建一个button按钮,然后给这个按钮设置一个id,在案例中把按钮的id设置为show。如图:

代码:

javascript显示和隐藏div的方法

3、然后创建一个隐藏的div,把需要隐藏的内容写到这个div上,然后给这个div设置一个id,在案例中设置案例的id为hide。如图:

代码:

我是隐藏的div

javascript显示和隐藏div的方法

4、给div设置隐藏的样式。在标签后面为id为hide设置样式display:none,这个样id为hide的div就会被隐藏掉了。如图:</p><p>样式代码:</p><pre><style> #hide{display: none;padding-top: 15px;} </style></pre><p><img src="/upload/otherpic54/5115.jpg" alt="javascript显示和隐藏div的方法"></p><p>5、为button按钮添加一个点击后隐藏事件。点击button按钮后,把隐藏的div的display修改为block,这样点击后div就会显示了。如图:</p><p>事件代码:</p><pre><script type="text/javascript">  window.onload = function(){ document.getElementById("show").onclick = function(){  document.getElementById("hide").style.display = "block"; }  } </script></pre><p><strong><img src="/upload/otherpic54/5116.jpg" alt="javascript显示和隐藏div的方法"></strong></p><p>感谢各位的阅读!关于“javascript显示和隐藏div的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!</p> <br> 网页名称:javascript显示和隐藏div的方法 <br> 当前URL:<a href="http://cdkjz.cn/article/giijgg.html">http://cdkjz.cn/article/giijgg.html</a> </div> <div class="g-return-wrapper clearfix"> <a href="http://www.cdkjz.cn/" class="home">返回首页</a> <a href="http://www.cdkjz.cn/news/" class="column">了解更多建站资讯</a> </div> </div> </div> <div class="full-related-news"> <h3 class="related-title">相关资讯</h3> <div class="related-news weblg"> <ul class="clearfix"> <li> <a href="/article/doocpig.html"> <h2 class="title">linux下电源管理命令 linux电源管理机制</h2> </a> </li><li> <a href="/article/doocpgo.html"> <h2 class="title">python有趣的函数 Python有趣的函数</h2> </a> </li><li> <a href="/article/doocjgj.html"> <h2 class="title">go语言爬虫爬取知乎 go语言做爬虫怎么样</h2> </a> </li><li> <a href="/article/doocihe.html"> <h2 class="title">vb.net布局设计 VB界面设计</h2> </a> </li><li> <a href="/article/doocpsp.html"> <h2 class="title">怎么备份服务器mysql 文件备份服务器</h2> </a> </li><li> <a href="/article/doocpsg.html"> <h2 class="title">python简单函数代码 Python函数大全</h2> </a> </li><li> <a href="/article/doocpdi.html"> <h2 class="title">vb.net进度条窗口 vb进度条控件在哪</h2> </a> </li><li> <a href="/article/doocpie.html"> <h2 class="title">go语言中文笔画 gogo的笔顺</h2> </a> </li> </ul> </div> </div> <div class="full-icontact-cover m-ft-contact"> <div class="weblg"> <div class="clearfix content"> <div class="motto"> 多年建站经验 </div> <div class="info"> <h3>多一份参考,总有益处</h3> <h2> 联系快上网,免费获得专属《策划方案》及报价</h2> <div class="msg"> <p>咨询相关问题或预约面谈,可以通过以下方式与我们联系</p> <h4> 大客户专线   成都:<a href="tel:+13518219792" rel="nofollow">13518219792</a>   座机:<a href="tel:02886922220" rel="nofollow">028-86922220</a> </h4> </div> </div> </div> <div class="btns clearfix"> <a href="https://wpa.qq.com/msgrd?v=3&uin=631063699&site=qq&menu=yes" target="_blank" rel="nofollow" class="oline">在线咨询</a> <a href="javascript:;" class="edit" rel="nofollow">提交需求</a> </div> </div> </div> <div class="footer-content"> <div class="weblg clearfix"> <div class="friend-links"> <h6 class="clearfix"> <span class="tilte">友情链接</span> <a class="exchagne" href="http://wpa.qq.com/msgrd?v=3&uin=631063699&site=qq&menu=yes">交换友情链接</a> </h6> <div class="link-list clearfix"> <div class="link-slider"> <a href="https://www.cdcxhl.com/h5.html" title="成都响应式网站" target="_blank">成都响应式网站</a><a href="http://www.cdhuace.com/" title="成都广告设计" target="_blank">成都广告设计</a><a href="http://m.cdcxhl.cn/mobile/ " title="手机网站设计" target="_blank">手机网站设计</a><a href="http://www.tyjierui.cn/" title="绵竹网站建设" target="_blank">绵竹网站建设</a><a href="http://www.cxjianzhan.com/seo/" title="快照排名" target="_blank">快照排名</a><a href="http://www.shjinzhi.cn/" title="兴宏源活动板房" target="_blank">兴宏源活动板房</a><a href="https://www.cdcxhl.com/quanwang.html" title="网络营销推广" target="_blank">网络营销推广</a><a href="http://www.qlmbz.com/" title="木包装箱" target="_blank">木包装箱</a><a href="https://www.cdcxhl.com/yunying.html" title="网站托管运营" target="_blank">网站托管运营</a><a href="http://chengdu.cdcxhl.cn/seo/ " title="成都网站推广" target="_blank">成都网站推广</a> </div> </div> </div> </div> <div class="full-foot-bottom"> <div class="weblg clearfix"> <p>成都网站建设公司地址:成都市青羊区太升南路288号锦天国际A座10层 建设咨询<a href="tel:028-86922220">028-86922220</a></p> <p> 成都快上网科技有限公司-四川网站建设设计公司 | <a href="http://www.miitbeian.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a> Copyright 2020,ALL Rights Reserved cdkjz.cn | <a href="http://www.cdkjz.cn/" target="_blank">成都网站建设</a> | © Copyright 2020版权所有.</p> <p>专家团队为您提供<a href="http://www.cdkjz.cn/" target="_blank">成都网站建设</a>,<a href="http://www.cdkjz.cn/" target="_blank">成都网站设计</a>,成都品牌网站设计,成都营销型网站制作等服务,成都建网站就找快上网! | 成都网站建设哪家好? | <a href="###">网站建设地图</a></p> </div> </div> </div> <script type="text/javascript" src="../js/idangerous.swiper.min.js"></script> <script type="text/javascript" src="../js/wow.min.js"></script> <script type="text/javascript" src="../js/jquery.mousewheel.min.js"></script> <script type="text/javascript" src="../js/jquery.placeholder.min.js"></script> <script type="text/javascript" src="../js/layout.js"></script> </body> </html> <script> $(".singlepage img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>