<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> .inner{ width:100px; white-space: pre-wrap; /* 自动换行操作 */ } </style> </head> <body> <textarea id="text"></textarea> <button id="btn">按钮</button> <!-- pre 中嵌套 inner --> <pre id="box"><div class="inner"></div></pre> <script> var box = document.getElementById(‘box‘); var btn = document.getElementById(‘btn‘); var text = document.getElementById(‘text‘); btn.onclick = function(){ box.getElementsByTagName(‘div‘)[0].innerHTML = text.value ; } </script> </body> </html>