溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

javascript額uh實(shí)現(xiàn)留言功能

發(fā)布時(shí)間:2022-01-18 17:08:48 來源:億速云 閱讀:141 作者:iii 欄目:web開發(fā)

這篇文章主要介紹了javascript額uh實(shí)現(xiàn)留言功能的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇javascript額uh實(shí)現(xiàn)留言功能文章都會(huì)有所收獲,下面我們一起來看看吧。

javascript實(shí)現(xiàn)留言的方法:1、創(chuàng)建一個(gè)HTML示例文件并輸入input標(biāo)簽;2、輸入script標(biāo)簽;3、通過js代碼“oPostBtn.onclick = function(){...}”實(shí)現(xiàn)留言即可。

javascript額uh實(shí)現(xiàn)留言功能

本文操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

javascript怎么實(shí)現(xiàn)留言?

JS原生編寫實(shí)現(xiàn)留言板功能

實(shí)現(xiàn)這個(gè)留言板功能比較簡(jiǎn)單,所以先上效果圖:
javascript額uh實(shí)現(xiàn)留言功能
實(shí)現(xiàn)用戶留言內(nèi)容,留言具體時(shí)間。

<script>

	window.onload = function(){
		
		var oMessageBox = document.getElementById("messageBox");
		var oInput = document.getElementById("myInput");
		var oPostBtn = document.getElementById("doPost");
		
		oPostBtn.onclick = function(){
			if(oInput.value){
				//寫入發(fā)表留言的時(shí)間
				var oTime = document.createElement("p");
				oTime.className = "time";
				var myDate = new  Date();
				oTime.innerHTML = myDate.toLocaleString();
				oMessageBox.appendChild(oTime);
				
				//寫入留言內(nèi)容
				var oMessageContent = document.createElement("p");
				oMessageContent.className = "message_content";
				oMessageContent.innerHTML = oInput.value;
				oInput.value = "";
				oMessageBox.appendChild(oMessageContent);
			}
			
		}
		
	}

</script>

通過獲取input的輸入焦點(diǎn)事件抓取內(nèi)容,傳遞給留言板的p來展示。

<body>
	<div class="content">
        <div class="title">用戶留言</div>
        <div class="message_box" id="messageBox"></div>
        <div><input id="myInput" type="text" placeholder="請(qǐng)輸入留言類容"><button id="doPost">提交</button></div>
    </div>
</body>

關(guān)于“javascript額uh實(shí)現(xiàn)留言功能”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“javascript額uh實(shí)現(xiàn)留言功能”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI