<大神>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://85l.net/l/519717732355713245.html">港澳通行证如果去拿,没有回执可以拿的到吗?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/1547278731485073427.html">雪佛兰开拓者到店实拍,配2.0T+9AT,本月中旬上市</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/1708459760790006020.html">这是什么人物?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/431392921542889812.html">汽车保养主要是做些什么项目?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/438637587788888164.html">我的华硕笔记本电脑工作的时候按到了开机键,电脑关机了,现在怎么也打不开,任何键都没什么反应。谢谢?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/1946302206880371428.html">广州南站怎麼搭地铁去荔湾区的十三行</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/577905172.html">去献血被告知血液不合格,说有梅毒,但是身上却没一点症状,怎么办?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/1433030462883809339.html">分手后我应该归还前男友给我买手机的钱吗</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/714988720629663965.html">建筑工地临时用电的一级配电箱应离地面多高</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/1675458273132187787.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://85l.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?d7381e8e13750926596c531b05a19c89"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>