<大神>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://aq8.net/125646005.html">求终极一班,终极一家,终极三国里的全部和全部歌的下载网址</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/1614238881213309587.html">如何辨识真假土蜂蜜</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/366602839.html">成都旅游要花多少钱 去5天左右 两个人</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/305397170005407564.html">我想找我的同学,我只知道她的名字,和曾经读过的高中请问怎样能找到她。</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/535631268.html">计算下列各式,并用幂的形式表示结果. (2x)^4 (xy^2)^3 (-3⼀2t)^3 (-3a^3)^2</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/1867672851177198147.html">两个电池并联后路端电压,内阻怎么计算?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/565190133959092724.html">英语单词“his”的对应词是什么?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/275668619.html">黄土高坡在中国哪里?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/1055178512084920699.html">如何判断自己有没有口臭?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://aq8.net/1110391710746183899.html">剖腹产后有哪些自我保健的方法?拜托了各位 谢谢</a></div> </div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <!-- 移动底部导航 --> <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://aq8.net/static/old/img/fhtop.png" alt="返回顶部" 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?d86df1760ee607dc5bff1a7aab937e8e"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>