用js編寫留言板
本文實(shí)例為大家分享了js編寫留言板的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{
margin:0px;
padding: 0px;
font-size: 12px;
}
.tie{
width: 70px;
height: 30px;
background:pink;
border-radius: 10%;
}
.an{
width: 70px;
height: 30px;
background:pink;
border-radius: 10%;
}
.allFather{
position: fixed;
left: 250px;
top: 0px;
border:1px solid gray;
width: 300px;
height: 300px;
}
.wenb{
width: 260px;
height:25px;
margin-top: 10px;
margin-left: 10px;
color: gray;
}
.two{
margin-top: 10px;
margin-left: 10px;
}
.jj{
width: 120px;
height: 25px;
}
.kk{
margin-top: 10px;
margin-left: 10px;
width: 260px;
}
.an{
margin-top: 10px;
margin-left: 10px;
}
</style>
</head>
<body>
<button class="tie">我要發(fā)帖</button>
<ul class="items"></ul>
<div class="allFather" style="display: none;">
<input type="text" value="請(qǐng)輸入標(biāo)題(1-60個(gè)字符)" class="wenb">
<div class="two">
所屬板塊
<select name="" id="wyd" class="jj">
<option value="">英雄聯(lián)盟</option>
<option value="">穿越火線</option>
<option value="">qq飛車</option>
<option value="">地下城與勇士</option>
<option value="">逆戰(zhàn)</option>
</select>
</div>
<textarea name="" id="" cols="30" rows="10" class="kk"></textarea>
<button "cz()" class="an">發(fā)布</button>
</div>
</body>
<script type="text/javascript">
//點(diǎn)擊時(shí)使發(fā)帖界面顯示
var tie = document.getElementsByClassName('tie')[0];
tie.onclick = function(){
document.getElementsByClassName('allFather')[0].style.display = "block";
}
//獲得節(jié)點(diǎn)上傳
var bt = document.getElementsByClassName("wenb")[0];//獲得標(biāo)題
var bk = document.getElementById('wyd');//獲得板塊
var jio = document.getElementsByClassName('kk')[0];//獲得多行文本框內(nèi)容
var time = new Date();//獲得時(shí)間
var nian = time.getFullYear();//獲得年份
var dt = time.getMonth();//獲得月份
var r = time.getDate();//獲得日期
var shi = time.getHours();//獲得小時(shí)
var fen = time.getMinutes();//獲得分鐘
//實(shí)現(xiàn)上傳
var items = document.getElementsByClassName('items')[0];//獲得ul的節(jié)點(diǎn)屬性
//實(shí)現(xiàn)創(chuàng)造新節(jié)點(diǎn)
//焦點(diǎn)聚集事件
bt.onfocus = function(){
bt.value = "";
}
function cz(){
//先創(chuàng)建li的節(jié)點(diǎn)
var Li = document.createElement('li');
//然后插入到ul中
items.appendChild(Li);
Li.style.listStyle = "none";
//創(chuàng)建圖片
var img = document.createElement('img');
Li.appendChild(img);//在li中插入圖片
var isz = ['../images/sdg.jpg','../images/dfggfhs.jpg'];//一個(gè)圖片的數(shù)組
var index = Math.floor(Math.random()*2);
img.style.width = "50px";
img.style.height = "50px";
img.style.borderRadius = "50%";
img.setAttribute('src',isz[index]);
//創(chuàng)建圖片右邊內(nèi)容的大盒子
var hfather = document.createElement('div');
Li.appendChild(hfather);//插入大盒子
//實(shí)現(xiàn)盒子左浮動(dòng)
hfather.style.display = "inline-block";
//創(chuàng)建標(biāo)題
var libt = document.createElement('p');
hfather.appendChild(libt);
libt.style.fontSize = "20px";
libt.style.color = "black";
libt.style.fontWeight = "bloder";
libt.style.marginBottom = "5px";
libt.innerHTML = bt.value;//填充內(nèi)容
//創(chuàng)建板塊
var text = "";
for(i = 0;i < bk.length; i++) {//下拉框的長(zhǎng)度就是它的選項(xiàng)數(shù).
if(bk[i].selected == true) {
text = bk[i].innerHTML;//獲取當(dāng)前選擇項(xiàng)的值.
}
}
var bkl = document.createElement('span');
hfather.appendChild(bkl);
bkl.style.color = "gray";
bkl.innerHTML = "板塊:" + text;
console.log(bkl.innerHTML);
//創(chuàng)建時(shí)間板塊
var tbk = document.createElement('span');
hfather.appendChild(tbk);
tbk.style.marginLeft = "15px";
tbk.style.color = "gray";
tbk.innerHTML = "發(fā)表時(shí)間:" + nian + "-" + (dt+1) + "-" + r + " " + shi + ":" + fen;
document.getElementsByClassName('allFather')[0].style.display = "none";
bt.value = "請(qǐng)輸入標(biāo)題(1-60個(gè)字符)";
jio.value = "";
bk[0].selected = true;
}
</script>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue實(shí)現(xiàn)留言板todolist功能
- react結(jié)合bootstrap實(shí)現(xiàn)評(píng)論功能
- vue實(shí)現(xiàn)評(píng)論列表功能
- Vuepress 搭建帶評(píng)論功能的靜態(tài)博客的實(shí)現(xiàn)
- 簡(jiǎn)易Vue評(píng)論框架的實(shí)現(xiàn)(父組件的實(shí)現(xiàn))
- vue.js評(píng)論發(fā)布信息可插入QQ表情功能
- vue.js實(shí)現(xiàn)用戶評(píng)論、登錄、注冊(cè)、及修改信息功能
- Vue.js實(shí)現(xiàn)文章評(píng)論和回復(fù)評(píng)論功能
- JavaScript實(shí)現(xiàn)留言板案例
- 基于vue和bootstrap實(shí)現(xiàn)簡(jiǎn)單留言板功能
相關(guān)文章
詳解JS數(shù)據(jù)類型的值拷貝函數(shù)(深拷貝)
這篇文章主要介紹了詳解JS數(shù)據(jù)類型的值拷貝函數(shù)(深拷貝)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-07-07
微信小程序?qū)崿F(xiàn)下滑到底部自動(dòng)翻頁(yè)功能
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)下滑到底部自動(dòng)翻頁(yè)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03
防止頁(yè)面url緩存中ajax中post請(qǐng)求的處理方法
這篇文章主要介紹了防止頁(yè)面url緩存中ajax中post請(qǐng)求的處理方式的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下2017-10-10
bootstrap里bootstrap動(dòng)態(tài)加載下拉框的實(shí)例講解
今天小編就為大家分享一篇bootstrap里bootstrap動(dòng)態(tài)加載下拉框的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
微信小程序?qū)崿F(xiàn)modal彈出框遮罩層組件(可帶文本框)
這篇文章主要給大家介紹了關(guān)于微信小程序?qū)崿F(xiàn)modal彈出框遮罩層組件(可帶文本框)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
微信小程序wxss如何引用外部CSS文件以及iconfont
這篇文章主要給大家介紹了關(guān)于微信小程序wxss如何引用外部CSS文件以及iconfont的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
詳解javascript立即執(zhí)行函數(shù)表達(dá)式IIFE
本文主要介紹了javascript立即執(zhí)行函數(shù)表達(dá)式IIFE的相關(guān)知識(shí)。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02

