Get the App
SLTechnology News&Howtos  ›  Development  › 

Javascript, uh, uh realizes the function of leaving messages.

Shulou Source: shulou.com Published: 2022-06-02 01:45:29 11月13日 Update

This article mainly introduces javascript uh to achieve message function related knowledge, content detailed and easy to understand, simple and fast operation, has a certain reference value, I believe everyone read this javascript uh to achieve message function article will have some gains, let's take a look at it.

javascript implementation of the message method: 1, create an HTML sample file and enter the input tag;2, enter the script tag;3, through the js code "oPostBtn.onclick = function(){...} "Leave a message.

Operating environment of this article: Windows 7 system, javascript version 1.8.5, Dell G3 computer.

How does javascript work?

JS native writing to achieve message board function

To achieve this message board function is relatively simple, so first on the renderings:

Realize the user message content, message specific time.

_window.onload = function(){ var oMessageBox = document.getElementById("messageBox"); var oInput = document.getElementById("myInput"); var oPostBtn = document.getElementById("doPost"); oPostBtn.onclick = function(){ if(oInput.value){ //Write the time of posting the message var oTime = document.createElement("p"); oTime.className = "time"; var myDate = new Date(); oTime[xss_clean] = myDate.toLocaleString(); oMessageBox.appendChild(oTime); //Write message content var oMessageContent = document.createElement("p"); oMessageContent.className = "message_content"; oMessageContent[xss_clean] = oInput.value; oInput.value = ""; oMessageBox.appendChild(oMessageContent); } } }

Capture content by getting input focus events and pass it to the p of the message board to display.

cshu message submitted About "javascript eh realize message function" the content of this article is introduced here, thank you for reading! I believe that everyone has a certain understanding of the knowledge of "javascript uh implementation message function". If you still want to learn more knowledge, please pay attention to the industry information channel.

Tags: Function content message board knowledge input time tag user article event code value simple operation effect effect drawing file article method easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Redmi Shulou Tech Info Shulou Information