Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report