就是如何点击盒子1中的链接,让盒子2中的内容改变(让盒子1中的a或者b链接到盒子2或者盒子3)
7条回答 默认 最新
- Stephen_112 2021-11-06 10:53关注
就是一个简单的js问题么,左面放几个button,给button加上事件,点击不同的button,右边显示不同的内容。就这么个效果吧。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> .container{ display: flex; flex-direction: row; } .left{ width: 30%; } .left button{ width: 100px; height: 50px; font-size: 21px; } .left div{ margin-top: 15px; } .right{ width: 50%; height: 300px; background-color: aliceblue; } </style> </head> <body> <div class="container"> <div class="left"> <div> <button id="red">red</button> </div> <div> <button id="green">green</button> </div> <div> <button id="blue">blue</button> </div> </div> <div id="right" class="right"></div> </div> </body> <script> document.getElementById('red').addEventListener('click',function(){ document.getElementById("right").style.backgroundColor = "red"; }); document.getElementById('green').addEventListener('click',function(){ document.getElementById("right").style.backgroundColor = "green"; }); document.getElementById('blue').addEventListener('click',function(){ document.getElementById("right").style.backgroundColor = "blue"; }); </script> </html>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 神经网络Sequential name=sequential, built=False
- ¥16 Qphython 用xlrd读取excel报错
- ¥15 单片机学习顺序问题!!
- ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
- ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
- ¥15 相敏解调 matlab
- ¥15 求lingo代码和思路
- ¥15 公交车和无人机协同运输
- ¥15 stm32代码移植没反应
- ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效