按照回车换行符给文本添加div标签

来源:互联网 发布:java实现post请求 编辑:程序博客网 时间:2024/06/03 14:51
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Testing</title>
</head>
<body>
<textarea id="txtArea" type="text" style="width:800px;height:400px;border:1px solid red;display:inline-block;" value=""></textarea>
      <button onclick="getArray()" style="display:inline">格式化</button>
  <textarea id="txtArea1" style="width:800px;height:400px;border:1px solid red;display:inline-block;" value=""></textarea>
<script type="text/javascript">
function getArray(){
 var aa = document.getElementById("txtArea").value.split("\n");
     var html = "";
for(var i=0;i<aa.length;i++){
html += "<div>"+aa[i]+"</div>" +"\n";
}
     document.getElementById("txtArea1").value = html;

}

</script>


</body>
</html>
原创粉丝点击