实战明星相册
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>1.实战明星相册</title> <style> .box{ width:500px; 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:0; padding: 0; overflow: hidden; } .box ul li{ list-style-type:none; float:left; background-color: skyblue; margin-left: 20px; } .box ul li a{ display: block; width:100px; height:40px; line-height: 40px; color: white; text-decoration: none; } .box ul li a:hover{ font-size: 1.2em; background-color: coral; } .box .pic{ width:450px; height:470px; border:1px solid lightgray; line-height: 1px; margin:auto; margin-top: 50px; } .box .pic img{ width:100%; height:100%; } </style> </head> <body> 知识点:1.js代码写在哪?2如何调用3.匿名函数 <div class="box"> <h2>明星相册</h2> <ul> <li><a href="../images/zly.jpg" title="《楚乔传》,《花千骨》,《陆贞传奇》..." onclick="changePic(this); return false;">赵丽颖</a></li> <li><a href="../images/gyy.jpg" title="《倚天屠龙记》,《咱们结婚吧》,《爱无悔》..." onclick="changePic(this); return false;">高圆圆</a></li> <li><a href="../images/sl.jpg" title="《那年花开月正园》,《甄嬛传》,《玉观音》..." onclick="changePic(this); return false;">孙俪</a></li> <li><a href="../images/fbb.jpg" title="《还珠格格》,《武媚娘传奇》,《我不是潘金莲》..." onclick="changePic(this); return false;">范冰冰</a></li> </ul> <div class="pic"> <img src="../images/001.jpg" alt="图片" id="img"> </div> <p id="info">dd</p> </body> </html> </div> <script> function changePic(pic){ //1.获取明星图片与简介 var picUrl = pic.href var picInfo = pic.title var picName = pic.innerHTML // alert(picInfo) //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>
运行实例 »
点击 "运行实例" 按钮查看在线实例