我想使用文本区域在 HTML 代码和预览 html 之间切换
当点击 HTML 时,它会显示隐藏文本区域的代码 当再次点击 HTML 时,它会再次显示
我想要设计这样的东西
我尝试过
<style> .container { width:500px; position: fixed; } .right-element { background: red; display: inline-block; position: absolute; right: 0; } </style> <div class="container"> <div class="right-element"> Preview </div> <textarea id="w3review" name="w3review" style="position:relative;width:100%;height:75%;resize: none; " ><h3>At w3schools.com you will learn how to make a website. They offer free tutorials in all web development technologies.</h3></textarea> </div>
您可以有另一个
div
专门用于显示预览。然后,当用户切换 HTML 视图时,将文本区域的值插入到div
的innerHTML
中并显示它。但这可能会让您的应用程序遭受 XSS 攻击,因此使用时要小心。