abstrait:<!DOCTYPE html> <html> <head> <title>智能在線客服系統(tǒng)</title> <style type="text/css"> div:nth-child(1){width: 450px; height: 650px;
<!DOCTYPE html> <html> <head> <title>智能在線客服系統(tǒng)</title> <style type="text/css"> div:nth-child(1){width: 450px; height: 650px; 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: 500px; 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 name="text" cols="50" rows="4"></textarea></td> <td align="left"><button type="button">發(fā)送</button></td> </tr> </table> </div> <script type="text/javascript"> var btn=document.getElementsByTagName('button')[0]; let text = document.getElementsByName('text')[0]; var list=document.getElementsByTagName('ul')[0]; var sum=0; btn.onclick=function(){ //創(chuàng)建一個(gè)新的標(biāo)簽li; var li=document.createElement('li'); var userCommer=text.value; if (userCommer.length ==0) { alert('請(qǐng)輸入想說(shuō)的話'); return false; } var me="我說(shuō):"; li.innerHTML=me+userCommer list.appendChild(li); text.value =''; sum += 1; //自動(dòng)回復(fù) setTimeout(function(){ var info=[ '不是我', '真的不是我', '都說(shuō)了住的不是我', '好吧,其實(shí)不是我' ]; //隨機(jī)回復(fù); //隨機(jī)數(shù)向下取整; //(0-1的隨機(jī)數(shù))*4=0-4的隨機(jī)數(shù),然后在向下取整; var temp=Math.floor(Math.random()*4) //得到隨機(jī)出現(xiàn)的對(duì)話; var speak=info[temp]; //在聲明一個(gè)標(biāo)簽li; var lis=document.createElement('li'); var people='客服說(shuō):'; //改變lis里面的內(nèi)容; lis.innerHTML=people+'<span style="color:red">'+speak+'</span>'; // 在ul里面添加lis' list.appendChild(lis); sum += 1; },2000) if (sum>10) { list.innerHTML=""; sum=0; } } </script> </body> </html>
Professeur correcteur:查無(wú)此人Temps de correction:2019-04-16 09:33:25
Résumé du professeur:完成的不錯(cuò)。以后學(xué)了php,就可以從數(shù)據(jù)庫(kù)拿回復(fù)話了。像京東那樣機(jī)器回復(fù)。