In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to achieve sentence inversion in javascript. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Methods: 1, use the "element .innerText" statement to get the text that needs to be reversed; 2, use the "text .split ('). Reverse (). Join (')" statement to reverse the text; 2, use the "element .innerText = inverted text" statement to write the inverted text into the tag element to display.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Sentence inversion based on javascript
The idea of realization is:
The first thing is to get the content of the sentence.
Because you only need text content, you can use the innerText attribute; it gets all the text in the tag (and its child tags), not the tag (or you can filter out all the tags). If there are multiple spaces or line breaks, resolve to a single space.
The obtained text content is then reversed, using the str.split ('). Reverse (). Join (') statement.
Finally, use the innerText attribute to rewrite the inverted text content back to the tag element for display.
Implementation code:
Welcome to!
Document.getElementById ("btn"). Onclick=function () {var div1=document.getElementById ("demo1"); var div2=document.getElementById ("demo2"); var text=div1.innerText; div2.innerText=text.split (''). Reverse (). Join (');}
Effect picture:
This is the end of the article on "how to achieve sentence inversion in javascript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.