当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 把textarea中字符串里含有的回车换行替换成<br>的javascript代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 把textarea中字符串里含有的回车换行替换成<br>的javascript代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 256 ::
收藏到网摘: n/a

1楼
textarea.value.replace(/\n/g, "<br>");
2楼
s=textarea.value.replace(/\r\n/g, "<br>");
3楼
按下的时候马上更换
V ID="a" contentEditable="true" style='border:1 solid black'>
其实以前早有很多人讨论过,代码比较多方法太可怕,自己用不到就没时间去研究,现在帮你试了一下,其实解决起来很简单了:)
<p>关于微软HTML编辑控件单击回车会插入<p>而不是<br>的解决方案</DIV> <p>
<div style='border:1 solid black' contentEditable="true">未经过脚本处理的编辑控件</div>
<script>
function a.onkeypress(){
if(event.keyCode==13){
var txtobj=document.selection.createRange()
txtobj.text==""?txtobj.text="\n":(document.selection.clear())&(txtobj.text="\n") //三目复合表达式,解决有被选文字时回车的光标定位问题
document.selection.createRange().select()
return false
}}
</script>
4楼
按下的时候马上更换
V ID="a" contentEditable="true" style='border:1 solid black'>
其实以前早有很多人讨论过,代码比较多方法太可怕,自己用不到就没时间去研究,现在帮你试了一下,其实解决起来很简单了:)
<p>关于微软HTML编辑控件单击回车会插入<p>而不是<br>的解决方案</DIV> <p>
<div style='border:1 solid black' contentEditable="true">未经过脚本处理的编辑控件</div>
<script>
function a.onkeypress(){
if(event.keyCode==13){
var txtobj=document.selection.createRange()
txtobj.text==""?txtobj.text="\n":(document.selection.clear())&(txtobj.text="\n") //三目复合表达式,解决有被选文字时回车的光标定位问题
document.selection.createRange().select()
return false
}}
</script>
5楼
按下的时候马上更换
V ID="a" contentEditable="true" style='border:1 solid black'>
其实以前早有很多人讨论过,代码比较多方法太可怕,自己用不到就没时间去研究,现在帮你试了一下,其实解决起来很简单了:)
<p>关于微软HTML编辑控件单击回车会插入<p>而不是<br>的解决方案</DIV> <p>
<div style='border:1 solid black' contentEditable="true">未经过脚本处理的编辑控件</div>
<script>
function a.onkeypress(){
if(event.keyCode==13){
var txtobj=document.selection.createRange()
txtobj.text==""?txtobj.text="\n":(document.selection.clear())&(txtobj.text="\n") //三目复合表达式,解决有被选文字时回车的光标定位问题
document.selection.createRange().select()
return false
}}
</script>