亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

js實(shí)現(xiàn)智能在線客服系統(tǒng)

Original 2019-03-17 16:34:15 394
abstrakt:看似簡單,但自己做的時候總是記不住那些方法和屬性,還是多記多練習(xí)<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-wid

看似簡單,但自己做的時候總是記不住那些方法和屬性,還是多記多練習(xí)


<!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>DOM實(shí)戰(zhàn):模擬智能在線客服系統(tǒng)</title>

<style>

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-type: none;

line-height: 2em;

overflow: hidden;

padding: 15px;

}

table {

width: 90%;

height: 80px;

margin: 0px 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>

<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>

//獲取到頁面中的相關(guān)元素

let btn = document.getElementsByTagName('button')[0];

let text = document.getElementsByName('text')[0];

let list = document.getElementsByTagName('ul')[0];

let sum = 0;  //計數(shù)器


//添加點(diǎn)擊事件,獲取用戶說的內(nèi)容并發(fā)送到窗口

btn.onclick = function(){

//獲取用戶提交的內(nèi)容

if (text.value.length === 0) {

alert('客官,是不是忘了想說什么了?');

return false;

}

let userComment = text.value;  //將用戶提交的內(nèi)容獲取并保存

text.value = '';


//創(chuàng)建一個li

let li = document.createElement('li');

//用戶頭像

//    let userPic = '<img src="inc/1.jpg" width="30" style="border-radius:50%">';

//將用戶輸入的信息添加到聊天窗口

li.innerHTML = userComment;

list.appendChild(li);

sum +=1;


//回復(fù),設(shè)置定時器,2秒后自動回復(fù)

setTimeout(function(){

let info = [

'真煩人,有話快說,別耽誤我學(xué)習(xí)',

'除了退款退貨,什么都可以問',

'說的啥,本姑娘怎么聽不明白呢?',

'在我覺得方便的時候再回復(fù)你',

'投訴我的人多了去了,哈哈哈。'

];

let temp = info[Math.floor(Math.random()*4)];

let reply = document.createElement('li');

//    let kefuPic = '<img src="inc/zly.jpg" width="30" style="border-radius: 50%">';

reply.innerHTML = '<span style="color:red">' + temp + '</span>';

list.appendChild(reply);

sum += 1;

},1000);


//清空窗口并將計數(shù)器清零

if (sum > 10){

list.innerHTML = '';

sum = 0;

}



}


</script>

</body>

</html>



Korrigierender Lehrer:查無此人Korrekturzeit:2019-03-18 09:12:31
Zusammenfassung des Lehrers:寫的還不錯。剛開始都記不住方法和屬性。 就算寫了10年代碼,也不可能記住全部的方法和屬于,只能記得常用的。繼續(xù)加油。

Versionshinweise

Beliebte Eintr?ge