1楼 textarea.value.replace(/n/g, "<br>"); 2楼 s=textarea.value.replace(/rn/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>
推荐阅读
JS 建立对象的方法
Objects are useful to organize information. 对于组织信息来讲对象是非常有用的 JavaScript Objects JS对象 Earlier in this tutorial we have seen that JavaScript has several built-in objects, like Strin>>>详细阅读
本文标题:把textarea中字符串里含有的回车换行替换成<br>的javascript代码
地址:http://www.17bianji.com/kaifa2/JS/30551.html
1/2 1