实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>实战1:选项卡</title> <style type="text/css"> h2 { text-align: center; } .box { width: 538px; height: 200px; background-color: white; border: 1px solid #ccc; margin: 20px auto; color: #363636; } .box > ul { margin: 0; padding: 0; background-color: #f8f8f8; overflow: hidden; } .box > ul li { list-style-type: none; width: 90px; height:36px; float:left; border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; text-align: center; line-height: 36px; } .box ul + span { float:right; width:110px; height: 36px; line-height: 36px; margin-top: -36px; } .box ul + span >a { color: #696969; text-decoration: none; } .box li.active { background-color: #fff; font-weight: bolder; border-bottom: none; border-top: 3px solid orangered; } .box div { display: none; } .box div ul { margin: 0; padding: 10px; list-style-type: none; } .box div ul li { line-height: 1.5em; } .box div ul li a { color: #636363; text-decoration: none; } .box div ul li a:hover { color: #000; } .box div ul li span { float: right; color: red; } </style> </head> <body> <h2>仿PHP中文网选项卡实战</h2> <div class="box"> <ul> <li class="active">范冰冰</li> <li>杨幂</li> <li>迪丽热巴</li> <li>赵丽颖</li> </ul> <span><a href="">更多下载>></a></span> <div style="display: block;"> <ul> <li><a href="">范冰冰 | 1</a><span>03-30</span></li> <li><a href="">范冰冰 | 2</a><span>03-30</span></li> <li><a href="">范冰冰 | 3</a><span>03-30</span></li> <li><a href="">范冰冰 | 4</a><span>03-30</span></li> </ul> </div> <div> <ul> <li><a href="">杨幂 | 1</a><span>03-30</span></li> <li><a href="">杨幂 | 2</a><span>03-30</span></li> <li><a href="">杨幂 | 3</a><span>03-30</span></li> <li><a href="">杨幂 | 4</a><span>03-30</span></li> </ul> </div> <div> <ul> <li><a href="">迪丽热巴 | 1</a><span>03-30</span></li> <li><a href="">迪丽热巴 | 2</a><span>03-30</span></li> <li><a href="">迪丽热巴 | 3</a><span>03-30</span></li> <li><a href="">迪丽热巴 | 4</a><span>03-30</span></li> </ul> </div> <div> <ul> <li><a href="">赵丽颖 | 1</a><span>03-30</span></li> <li><a href="">赵丽颖 | 2</a><span>03-30</span></li> <li><a href="">赵丽颖 | 3</a><span>03-30</span></li> <li><a href="">赵丽颖 | 4</a><span>03-30</span></li> </ul> </div> </div> <script type="text/javascript"> var box = document.getElementsByClassName('box')[0] var ul = box.getElementsByTagName('ul')[0] var tab = ul.getElementsByTagName('li') var list = box.getElementsByTagName('div') for (var i=0; i<tab.length; i++) { tab[i].index = i tab[i].onmouseover = function (){ for (var i=0; i<tab.length; i++) { tab[i].className = '' list[i].style.display = 'none' } this.className = 'active' list[this.index].style.display = 'block' } } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>2.仿机器人聊天窗口</title> <style type="text/css"> div:nth-child(1) { width: 450px; height: 500px; background-color: lightskyblue; margin: 30px auto; color: #333; box-shadow: 2px 2px 2px #808080; } h2 { text-align: center; margin-bottom: -10px; } div:nth-child(2) { width: 400px; height: 350px; border: 4px double green; background-color: #efefef; margin: 20px auto 10px; } ul { list-style: none; line-height: 2em; overflow: hidden; padding: 15px; } table { width: 90%; height:80px; margin: auto; } textarea{ border: none; resize: none; background-color: lightyellow; } button { width: 60px; height: 40px; background-color: seagreen; color: white; border: none; } button:hover { cursor: pointer; background-color: orange; } </style> </head> <body> <div> <h2>在线客服</h2> <div contenteditable="true"> <ul> <li></li> </ul> </div> <table> <tr> <td align="right"><textarea cols="50" rows="4" name="text"></textarea></td> <td align="left"><button type=button>发送</button></td> </tr> </table> </div> <script type="text/javascript"> var btn = document.getElementsByTagName('button')[0] var text = document.getElementsByName('text')[0] var list = document.getElementsByTagName('ul')[0] var sum = 0 btn.onclick = function () { if (text.value.length == 0) { alert('忘记输入内容了吧') return false } var userComment = text.value text.value = '' var li = document.createElement('li') li.innerHTML = userComment var userPic = '<img src="../images/ym.jpg" width="30" style="border-radius:50%">' li.innerHTML = userPic+userComment list.appendChild(li) sum += 1 setTimeout(function(){ var info = ['你好烦人','除了退货,退款,维修,什么问题都可以问','啥事呀,说,快点','哈哈哈哈'] var temp = info[Math.floor(Math.random()*3)] var reply = document.createElement('li') var kefuPic = '<img src="../images/fbb.jpg" width="30" style="border-radius:50%;">' reply.innerHTML = kefuPic + '<span style="color:red">'+temp+'</span>' list.appendChild(reply) sum += 1 },2000) if (sum > 10) { list.innerHTML = '' sum = 0 } } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例