简体   繁体   English

如何使用 JavaScript 将 TextArea 文本旋转 180 度

[英]How to rotate TextArea text by 180 degree using JavaScript

I am trying to rotate all alphabets, number and symbols in 180 degree, simply I mean rotating text upside down.我正在尝试将所有字母、数字和符号旋转 180 度,我的意思是颠倒旋转文本。 But the code is not working, what I am trying to do is possible with this code?但是代码不起作用,我想用这段代码做些什么?

Note : I want to rotate the text written inside TextArea not want to rotate the TextArea.注意:我想旋转 TextArea 中写入的文本,不想旋转 TextArea。

JsFiddle提琴手

Code:代码:

<!DOCTYPE html>
<html>
<body>

<form>
<textarea  id="textArea1" style="height: 100px; width: 468px;"></textarea><br />
<br />
<input onclick="myFunction()" type="button" value="Flip Text" /><br />
<br />

<textarea id="textArea2" style="height: 100px; width: 468px;"></textarea>
 
</form>

<script>
function myFunction() {

  document.getElementById("textArea2").value =  document.getElementById("textArea1").css('transform', 'rotate(180deg)');
  
}
</script>

</body>
</html>

Change your function content from将您的 function 内容从

document.getElementById("textArea2").value =  document.getElementById("textArea1").css('transform', 'rotate(180deg)');

to

document.getElementById("textArea1").style.transform  = 'rotate(180deg)';

within youe textarea style="" add transform property as在你的 textarea style=""中添加转换属性为

<textarea  id="textArea1" style="height: 100px; width: 468px; transform: rotate(180deg)"></textarea><br />

you asked on button click you have to rotate so under clickFunction you have add a line as:您在单击按钮时询问您必须旋转,因此在 clickFunction 下您添加了一行:

clickFunction(){
   document.getElementById('textArea1').style.transform = 'rotate(180deg)';
}

 function myFunction() { document.getElementById('rotatedText').innerText = document.getElementById("inputArea").value; }
 #rotatedText { width: 468px; border: 1px solid #000; margin-top: 5px; -moz-transform: scale(1, -1); -webkit-transform: scale(1, -1); -o-transform: scale(1, -1); -ms-transform: scale(1, -1); transform: scale(1, -1); }
 <:DOCTYPE html> <html> <body> <form> <textarea id="inputArea" style="height; 100px: width; 468px.">I AM READY TO FLIP.</textarea> <br/> <input onclick="myFunction()" type="button" value="Flip Text" /> <br /> <div id="rotatedText" contenteditable="true"> </div> </form> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM