<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>每天一個JavaScript實例-處理textarea中的字符成每一行</title> <script> function clicka(){ console.log("aaa"); var aa = document.getElementById("text"); var lines = aa.value.split("\n"); var bbb = document.getElementById("result"); var string = ""; for(i=0;i<lines.length;i++){ string+= lines[i]+"<br />";////</br> 和<br /> 應該用 <br /> } bbb.innerHTML=string } </script> </head> <body> <textarea id="text" placeholder="請輸入多行文字"></textarea> <div id = "result"></div> <a href="javascript:void(0);" onClick="clicka()">處理換行</a> </body> </html>