Correction status:Uncorrected
Teacher's comments:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>风景展示表</title> <style type="text/css"> .box { width: 600px; height: 700px; background-color: #efefef; border: 1px solid lightgray; margin: 20px auto; text-align: center; color: #636363; box-shadow: 2px 2px 2px #999; } .box ul { margin-left:50px; padding:0; /*将ul转为BFC独立块,使之不受内部浮动元素的影响*/ overflow: hidden; } .box ul li { list-style-type: none; float:left; background-color: lightgreen; margin-left: 20px; } .box ul li a { display: block; width: 100px; height: 40px; line-height: 40px; color: black; text-decoration: none; } .box ul li:hover { /*当鼠标放在区块上面的时候字体变大,背景变色*/ font-size:1.2em; background-color: orange; } .box .pic { width: 500px; height:450px; border: 1px solid lightgray; /*消除img标签底部的空间区*/ line-height: 1px; margin: auto; margin-top: 40px; } .box .pic img { width: 100%; height: 100%; } .box .pic img:hover { /*border-radius: 50%;*/ } </style> </head> <body> <div class="box"> <h2>风景展示表</h2> <ul> <li> <a href="images/1.png" title="平静秋水,似水流年" onclick="changePic(this);return false">湖水</a> </li> <li> <a href="./images/2.png" title="茶香满溢,神清气爽" onclick="changePic(this);return false">茶园</a> </li> <li> <a href="./images/3.png" title="荷兰的浪漫~" onclick="changePic(this);return false">风车</a> </li> <li><a href="./images/4.png" title="温柔的海风" onclick="changePic(this);return false">大海</a></li> </ul> <div class="pic"> <img src="../images/zwt.png" alt="" id="img"> </div> <p id='info'></p> </div> <script type="text/javascript"> function changePic(pic) { //1.获取目标对象 var picUrl = pic.href var picInfo = pic.title var picName = pic.innerHTML //2.获取被替换掉的元素 var img = document.getElementById('img') var p = document.getElementById('info') //3. 讲对象和元素进行替换 img.src = picUrl p.innerHTML = picName+':'+picInfo p.innerHTML = '<span style="color:coral">'+picName+':'+picInfo+'</span>' } </script> </body> </html>
点击 "运行实例" 按钮查看在线实例