Home  >  Article  >  Web Front-end  >  A JavaScript handles characters in a textarea into each line instance_javascript tips

A JavaScript handles characters in a textarea into each line instance_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:35:501327browse
  <!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>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn