JavaScript實現(xiàn)留言板案例
更新時間:2020年03月17日 14:55:15 作者:故里有長安、
這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)留言板案例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了JavaScript實現(xiàn)留言板功能的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>留言板</title> <style type="text/css"> #div1{ width: 400px; height: 200px; background-color: antiquewhite; } span{ color: blue; text-decoration: underline; } </style> </head> <body> <div id="div1"> 姓名:<input type="text" name="user" id="username" /><br /> 內(nèi)容:<textarea rows="10" cols="40" id="info"> </textarea> <input type="button" value="留言" id="btn" /><br /> </div> <h3>留言板</h3><br /> <div id="div2"> </div> </body> <script type="text/javascript"> var userInput = document.getElementById("username"); var infoInput = document.getElementById("info"); var btn = document.getElementById("btn"); var div2 = document.getElementById("div2"); btn.onclick = function(){ var user = userInput.value; var info = infoInput.value; var divUser = document.createElement("div"); divUser.innerText = user; divUser.style.backgroundColor = "darkgrey"; divUser.style.width = "400px"; divUser.style.height = "30px"; div2.appendChild(divUser); var divInfo = document.createElement("div"); divInfo.innerText = info; divInfo.style.backgroundColor = "antiquewhite"; divInfo.style.width = "400px"; divInfo.style.height = "80px"; div2.appendChild(divInfo); var del = document.createElement("span"); del.innerText = "刪除"; del.style.float = "right"; divInfo.appendChild(del); del.onclick = function(){ divUser.remove(); divInfo.remove(); del.remove(); } } </script> </html>
showtime:
點擊刪除,可以刪除留言:
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
使用JS批量選中功能實現(xiàn)更改數(shù)據(jù)庫中的status狀態(tài)值(批量展示)
我們在開發(fā)項目的時候經(jīng)常會在后臺管理時用到批量展示功能來動態(tài)的修改數(shù)據(jù)庫的值。下面以修改數(shù)據(jù)庫的status狀態(tài)值來實現(xiàn)批量展示功能2016-11-11