[英]How to rotate TextArea text by 180 degree using JavaScript
我正在尝试将所有字母、数字和符号旋转 180 度,我的意思是颠倒旋转文本。 但是代码不起作用,我想用这段代码做些什么?
注意:我想旋转 TextArea 中写入的文本,不想旋转 TextArea。
代码:
<!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>
将您的 function 内容从
document.getElementById("textArea2").value = document.getElementById("textArea1").css('transform', 'rotate(180deg)');
至
document.getElementById("textArea1").style.transform = 'rotate(180deg)';
在你的 textarea style=""
中添加转换属性为
<textarea id="textArea1" style="height: 100px; width: 468px; transform: rotate(180deg)"></textarea><br />
您在单击按钮时询问您必须旋转,因此在 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.