<大神>js如何实现点击一个按钮隐藏一个div,然后该div上有一个按钮,点击后隐藏,然后在显示另外一个div

2024-11-23 06:19:53
推荐回答(1个)
回答1:

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

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

3、然后创建一个隐藏的div,把需要隐藏的内容写到这个div上,然后给这个div设置一个id。

4、给div设置隐藏的样式。在标签后面为id为hide设置样式display:none,这个样id为hide的div就会被隐藏掉了。</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F86d6277f9e2f07083ae9e856e624b899a801f2fc%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/86d6277f9e2f07083ae9e856e624b899a801f2fc"></p> <p>5、为button按钮添加一个点击后隐藏事件。点击button按钮后,把隐藏的div的display修改为block,这样点击后div就会显示了。</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2Fa1ec08fa513d269772e3c50b5afbb2fb4316d8b0%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/a1ec08fa513d269772e3c50b5afbb2fb4316d8b0"></p> <p>6、保存好html后使用浏览器打开,点击button按钮就会发现隐藏的div就会显示出来了。</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F7aec54e736d12f2ec235633640c2d562853568b0%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/7aec54e736d12f2ec235633640c2d562853568b0"></p></p> </div> </div> <div class="clear"></div> </div> </div> </div> <div class="wendaright"> <div class="wdluluerwema"> <div class="wdxgwttop">相关问答</div> <div class="wdxgwtnr"> </div> <div class="clear"></div> </div> <!-- 其他随机问答['id'=>alphaID($like['zid'])] --> <div class="wdluluerwema"> <div class="wdxgwttop">最新问答</div> <div class="wdxgwtnr"> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/751364293833408772.html">求助一道定积分的极限的高数题</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/203743143710889725.html">对方微信给我删除了,我发好友验证,咋发送失败呢</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/461781100622587845.html">关于低保问题?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/1738543973268942507.html">农商银行怎样修改预留手机号码?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/209317608.html">上课讲空话,就让让学生写1500字的检讨算犯法吗?怎么保护?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/1175051137233439339.html">李莉有6个外形相同的兵乓球,其中一个略重一些,她想找出5个质量相同的兵乓球。你能用天平找出来吗?你</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/265429212.html">从烟台到大连怎么去最便宜呢?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/431340394191511572.html">酷狗音乐怎么上传到抖音上?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/617312541207069372.html">梦见回到学生时代在上课,还有好多老同学</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/2208609895847231148.html">305x150=什么列竖式怎么列</a></div> </div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <!-- 移动底部导航 --> <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://191i.com/static/old/img/fhtop.png" title="返回顶部"></a></div> <div class="dibu"> <div class="dibu"> </div> </div> <div class="banquan"> <p>内容全部来源于网络收集,如有侵权,请联系网站删除:QQ:24596024</p> </div> </div> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?530214f19d678452e8fa4098a936ce38"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>