サマリー:按照老師的思路自己寫(xiě)出來(lái)了,模擬只能在線客服系統(tǒng)。感覺(jué)老師的思路清晰,代碼簡(jiǎn)潔。很容易掌握。很感恩老師的教學(xué)以下是HTML+CSS+JS代碼:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <me
按照老師的思路自己寫(xiě)出來(lái)了,模擬只能在線客服系統(tǒng)。感覺(jué)老師的思路清晰,代碼簡(jiǎn)潔。很容易掌握。很感恩老師的教學(xué)
以下是HTML+CSS+JS代碼:
<!DOCTYPE html> <html lang="en"> <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>Document</title> <style> .chart { width: 550px; height: 600px; margin: 20px auto; background-color: cadetblue; border: 2px solid red } .chart ul { margin: 20px auto; padding: 0; width: 500px; height: 400px; background-color: bisque } .chart li{ list-style: none; height:30px; font-size: 12px; line-height:30px; margin-top:10px; padding:5px; } .chart li:nth-child(even){ color: red; text-align: right } .chart li:nth-child(even) img{ float: right } .chart li img{ width: 30px; height: 30px; float: left; margin-right: 5px; border-radius: 50%; } .chart h3 { width: 50%; margin: 10px auto; text-align: center; height: 40px; line-height: 40px; color: white } .write { width: 500px; margin: 15px auto; } .write textarea { width: 430px; float: left; height: 40px; } .write button { float: right; width: 60px; border: none; color: white; height: 45px; background-color: green } </style> </head> <body> <div class="chart"> <h3>模擬智能在線客服系統(tǒng)</h3> <ul> </ul> <div class="write"> <textarea name='text'></textarea> <button>發(fā)送</button> </div> </div> <script> let ul = document.getElementsByTagName('ul')[0]; let text = document.getElementsByName('text')[0]; let btn=document.getElementsByTagName('button')[0]; let tx='<img src="images/tx.jpg"/>'; let sum=0 btn.onclick=function(){ let li = document.createElement('li'); li.innerHTML=tx+text.value; ul.appendChild(li); text.value=''; sum+=1; // 設(shè)置2秒鐘后自動(dòng)恢復(fù) setTimeout(function(){ // 自動(dòng)回復(fù)信息模板 let info=[ '請(qǐng)描述你的問(wèn)題', '請(qǐng)您重復(fù)描述你的問(wèn)題', '請(qǐng)您再重復(fù)一遍你的問(wèn)題', '好的', '嗯,在呢', '今天太晚了,明天再說(shuō)吧。', ] let li=document.createElement('li'); let Kfpic='<img src="images/tx2.jpg"/>'; let hf=info[Math.floor(Math.random()*5)]; li.innerHTML=Kfpic+hf; ul.appendChild(li); },2000) } </script> </body> </html>
添削の先生:韋小寶添削時(shí)間:2019-01-20 09:25:19
先生のまとめ:寫(xiě)的很不錯(cuò) js還是很有意思的吧 js還可以寫(xiě)出很多好玩的東西 甚至還可以寫(xiě)一些小游戲 這種課后有空可以研究研究哦