JavaScript實現(xiàn)網(wǎng)頁留言板功能
JavaScript(JS)網(wǎng)頁?留言板,供大家參考,具體內(nèi)容如下
在使用網(wǎng)頁進行沖浪時,經(jīng)常會發(fā)表自己的留言。發(fā)布留言的留言板是怎么做的呢?
制作一個簡單的留言板。
首先需要一個textarea框,旁邊放置一個按鈕,然后需要一個ul標簽,里面不需要放置li元素,用CSS加以簡單的修飾。
緊接著獲取元素,在點擊按鈕后,創(chuàng)建一個li,將文本框里面的賦值給li,將li插入到ul的第一個孩子的前面。
<!DOCTYPE html><html lang='zh-CN'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <title>留言發(fā)布</title> <style> body { margin: 200px; } *{ margin: 0px; padding: 0px; } li { list-style: none; width: 500px; height: 30px; margin-top: 5px; border: 1px solid black; background-color: pink; } textarea{ width: 200px; height: 80px; } </style></head><body> <textarea name='' id=''></textarea> <button>發(fā)布</button> <ul> </ul> <script> //獲取元素 var btn = document.querySelector(’button’); var text = document.querySelector(’textarea’); var ul = document.querySelector(’ul’); //注冊時間 btn.onclick = function(){ if(text.value == ’’){alert('您沒有輸入內(nèi)容。')return false; }else{var li = document.createElement(’li’);li.innerHTML = text.value;//ul.appendChild(li);ul.insertBefore(li,ul.children[0]) } text.value=’’; } </script></body></html>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. chat.asp聊天程序的編寫方法2. ASP.NET Core按用戶等級授權(quán)的方法3. CSS 使用Sprites技術(shù)實現(xiàn)圓角效果4. 詳解瀏覽器的緩存機制5. 利用FastReport傳遞圖片參數(shù)在報表上展示簽名信息的實現(xiàn)方法6. phpstudy apache開啟ssi使用詳解7. ASP常用日期格式化函數(shù) FormatDate()8. 怎樣才能用js生成xmldom對象,并且在firefox中也實現(xiàn)xml數(shù)據(jù)島?9. HTML中的XML數(shù)據(jù)島記錄編輯與添加10. 推薦一個好看Table表格的css樣式代碼詳解
