摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8">
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>智能在線客服系統(tǒng)布局二:javascript</title> <style> * { margin: 0; padding: 0; } .main { margin: 20px auto; width: 450px; height: 680px; background: #87CEFA; box-shadow: 2px 2px 10px #888; border-radius: 10px; } h2 { text-align: center; padding: 10px 0; color: #fff; border-bottom: 2px solid #fff; } .content { width: 400px; height: 500px; background: #EFEFEF; margin: 20px auto 10px; border: 6px double lightgreen; } ul { list-style: none; line-height: 2em; overflow: hidden; padding: 15px; } .sub { float: left; width: 480px; margin: 10px auto; position: relative; } textarea { width: 350px; height: 50px; resize: none; outline: none; position: absolute; left: 20px; border: 0; font-size: 16px; color: red; } button { width: 58px; height:50px; background: red; color: #fff; position: absolute; left: 370px; border: 0; } button:hover { background: black; cursor: pointer; } </style> </head> <body> <div> <h2>在線客服</h2> <div> <ul> <li></li> </ul> </div> <div> <textarea name="text"></textarea> <button type="button">發(fā)送</button> </div> </div> <script> var text = document.getElementsByTagName('textarea')[0]; var ul = document.getElementsByTagName('ul')[0]; var btn = document.getElementsByTagName('button')[0]; var sum = 0; text.focus(); btn.onclick = function() { if (text.value.length === 0) { alert('您好,請輸入內(nèi)容'); return false; } var userContent = text.value; text.value = ''; var li = document.createElement('li'); li.innerHTML = userContent; var userPic = '<img src="dom/inc/peter.jpg" width="30" style="border-radius:50%">'; li.innerHTML = userPic + ' ' + userContent; ul.appendChild(li); sum += 1; setTimeout(function() { var info = [ '您好,有什么需要能幫助您的?', '今天的天氣挺不錯!', '周末大酬賓,讓利50%,歡迎選購!', '退貨還是換貨了?', '活動還有2天的時間,抓緊行動了。' ]; var temp = info[Math.floor(Math.random() * 5)]; var reli = document.createElement('li'); var kefuPic = '<img src="dom/inc/zly.jpg" width="30" style="border-radius:50%;">'; reli.innerHTML = kefuPic + ' ' + '<span style="color:red">' + temp + '</span>'; ul.appendChild(reli); sum += 1; }, 2000); if (sum > 10) { ul.innerHTML = ''; sum = 0; } } </script> </body> </html>
批改老師:韋小寶批改時間:2019-03-09 09:12:30
老師總結(jié):寫的還算是很不錯的 沒事要記得多去練習練習哦 可以考慮使用jQuery來把這個項目改寫一下