abstrait:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{margin: 0px;padding: 0px;} .div{ height: 550px; width: 300px; background:#ccc; text-align: center; margin-left: 50px; margin-top:10px; } .div div{ padding-top: 10px; } .content{ list-style: none; width: 260px; margin: 10px auto; height: 380px; color:black; font-size:14px; background: white; } .content li{ text-align: left; margin:10px; } .text{ margin: 10px 0; width: 260px; height: 30px; } .submit{ width: 262px; height:30px; margin: 0px auto; border:none; background:lightblue; color:#fff; border-radius: 5px; } p{ height:40px; line-height: 40px; font-weight: bold; font-size:20px; background: yellowgreen; } </style> </head> <body> <div class="div"> <p>在線客服</p> <div> <ul class="content"></ul> </div> <textarea class="text"></textarea><br> <button class="submit">發(fā)表</button> </div> </body> <script type="text/javascript"> let content = document.querySelector('.content'); let text = document.querySelector('.text'); let submit = document.querySelector('.submit'); submit.onclick = function(){ let value = text.value; let li = document.createElement("li"); li.innerHTML="游客:"+value; content.appendChild(li); let li1 = document.createElement("li"); li1.style.color="red"; li1.innerHTML = "客服1:您好,很高興為您服務(wù)!"; content.appendChild(li1); } </script> </html>
簡(jiǎn)單的在線客服操作:
先獲取所有元素的對(duì)象
其次在根據(jù)用戶提交的內(nèi)容,去生成相應(yīng)的標(biāo)簽
再將對(duì)應(yīng)的標(biāo)簽元素放進(jìn)對(duì)應(yīng)的父級(jí)元素內(nèi)
最后在進(jìn)行回復(fù),并從夫2、3部
顯示效果如下:
Professeur correcteur:西門大官人Temps de correction:2019-03-03 13:26:05
Résumé du professeur:布局和js代碼實(shí)現(xiàn)很好,最好把全局變量放到onclick的方法中去,變成局部變量使用