将textarea里的内容存入数据库时,会自动将回车换行符过滤成空格,也会将多个空格转换成一个空格,即:将\n等换成 “  ”存入数据库

因此为了将内容从数据库中按照原来格式读出写入到html 就必须在文本插入数据库之前将

换行符转化成<br />

 

本例:

  content=window.document.getElementById('content');   

sub=window.document.getElementsByTagName('form')[0];   

sub.onsubmit=function(){    x=content.value;    

   content.value=x.replace(/\n/g,"<br/>");    y=content.value;      

}

这里content是textarea的id;

相关文章:

  • 2022-01-29
  • 2021-09-20
  • 2021-08-19
  • 2021-07-01
猜你喜欢
  • 2021-12-29
  • 2021-11-04
  • 2021-05-23
相关资源
相似解决方案