JavaScript實(shí)現(xiàn)留言板案例
本文實(shí)例為大家分享了JavaScript實(shí)現(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:

點(diǎn)擊刪除,可以刪除留言:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS實(shí)現(xiàn)的倒計(jì)時(shí)效果實(shí)例(2則實(shí)例)
這篇文章主要介紹了JS實(shí)現(xiàn)的倒計(jì)時(shí)效果,列舉了兩則JavaScript倒計(jì)時(shí)效果代碼供大家參考,原理基本相似,代碼簡潔實(shí)用,需要的朋友可以參考下2015-12-12
使用JS批量選中功能實(shí)現(xiàn)更改數(shù)據(jù)庫中的status狀態(tài)值(批量展示)
我們?cè)陂_發(fā)項(xiàng)目的時(shí)候經(jīng)常會(huì)在后臺(tái)管理時(shí)用到批量展示功能來動(dòng)態(tài)的修改數(shù)據(jù)庫的值。下面以修改數(shù)據(jù)庫的status狀態(tài)值來實(shí)現(xiàn)批量展示功能2016-11-11
js 限制數(shù)字 js限制輸入實(shí)現(xiàn)代碼
在工作中經(jīng)常會(huì)遇到j(luò)s限制輸入方面的要求,本文將詳細(xì)介紹其實(shí)現(xiàn)原理,需要的朋友可以參考下2012-12-12
轉(zhuǎn)換layUI的數(shù)據(jù)表格中的日期格式方法
今天小編就為大家分享一篇轉(zhuǎn)換layUI的數(shù)據(jù)表格中的日期格式方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-09-09
echarts地圖繪制自定義標(biāo)記實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于echarts地圖繪制自定義標(biāo)記實(shí)現(xiàn)的相關(guān)資料,ECharts地圖是一個(gè)功能強(qiáng)大的數(shù)據(jù)可視化工具,基于百度ECharts開源項(xiàng)目開發(fā)而成,它主要用于在網(wǎng)頁中展示各種地理數(shù)據(jù)和地圖的信息,需要的朋友可以參考下2023-11-11

