abstrak:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>DOM實(shí)戰(zhàn):模擬智能在線客服系統(tǒng)&
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>DOM實(shí)戰(zhàn):模擬智能在線客服系統(tǒng)</title> <style type="text/css"> /*找到其父元素下的第一個(gè)div,這種寫法很少見吧?寫著亂亂的感覺, 多個(gè)父的時(shí)候是選擇第一個(gè)父級,第二個(gè)父級會控制到旗下的第一個(gè)元素 是不是div如果是那就被控制*/ div:nth-child(1) { width: 450px; height: 650px; background-color: lightskyblue; margin: 30px auto; color: #333; box-shadow: 2px 2px 2px #808080 } /*給"在線客服”標(biāo)樣式*/ 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; /*border: 1px solid red;*/ overflow: hidden; padding: 15px; } table { width: 90%; height:80px; margin: auto; } textarea{ /*width: 300px;*/ border: none; resize: none; background-color: lightyellow; } button { width: 60px; height: 40px; background-color: seagreen; color: white; border: none; /*text-align: left;*/ } button:hover { cursor: pointer; background-color: orange; } </style> </head> <body> <div> <h2>在線客服</h2> <!--contenteditable="true"屬性則可以對該標(biāo)簽進(jìn)行編輯--> <div contenteditable="true"> <ul> <li></li> </ul> </div> <table> <tr> <td align="right"> <!-- cols 和 rows 屬性來規(guī)定 textarea 的尺寸cols是行,rows是列--> <textarea cols="50" rows="4" name="text"></textarea> </td> <td align="left"> <button type=button>發(fā)送</button> </td> </tr> </table> </div> <script type="text/javascript"> //先獲取到所有dom元素 //通過按鈕標(biāo)簽名獲取元素:ElementsByTagName let btn = getElementsByTagName('button')[0]; //通過textarea文本域name名獲取元素:getElementsByName let text = document.getElementsByName('text')[0]; //通過按鈕標(biāo)簽名獲取元素:ElementsByTagName let list = document.getElementsByTagName('ul')[0]; //計(jì)數(shù)器 let sum = 0; </script> </body> </html>