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)擊刪除,可以刪除留言:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
原生JavaScript生成GUID的實(shí)現(xiàn)示例
GUID(全局統(tǒng)一標(biāo)識(shí)符)是指在一臺(tái)機(jī)器上生成的數(shù)字,下面為大家介紹下原生JavaScript生成GUID的實(shí)現(xiàn),需要的朋友不要錯(cuò)過2014-09-09
Javascript操縱Cookie實(shí)現(xiàn)購(gòu)物車程序
Javascript操縱Cookie實(shí)現(xiàn)購(gòu)物車程序...2006-11-11
JavaScript 實(shí)現(xiàn)鍋拍灰太狼小游戲
這篇文章主要介紹了JavaScript 實(shí)現(xiàn)鍋拍灰太狼小游戲,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09
javascript解析json格式的數(shù)據(jù)方法詳解
這篇文章主要介紹了javascript解析json格式的數(shù)據(jù)方法詳解,文章通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
怎樣用Javascript實(shí)現(xiàn)函數(shù)柯里化與反柯里化
這篇文章主要介紹了怎樣用Javascript實(shí)現(xiàn)函數(shù)柯里化與反柯里化,想了解函數(shù)柯里化的同學(xué),可以參考下2021-04-04
JavaScript實(shí)現(xiàn)搜索框的自動(dòng)完成功能(一)
在很多需要搜索的網(wǎng)站, 都會(huì)有一個(gè)自動(dòng)完成的搜索框. 方便用戶查找他們想要的搜索詞. 幫助用戶快速找到自己想要的結(jié)果.接下來通過本文給大家介紹JavaScript實(shí)現(xiàn)搜索框的自動(dòng)完成功能(一),需要的朋友參考下吧2016-02-02
JS實(shí)現(xiàn)圖片預(yù)加載之無序預(yù)加載功能代碼
這篇文章主要介紹了JS實(shí)現(xiàn)圖片預(yù)加載之無序預(yù)加載功能代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-05-05

