当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 关于开发在线网页编辑器按回车会输入<p>而不是<br>的解决方法

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 中的 关于开发在线网页编辑器按回车会输入<p>而不是<br>的解决方法


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

<DIV ID="a" contentEditable="true" style='border:1 solid black'>其实以前早有很多人讨论过,代码比较多方法太可怕,自己用不到就没时间去研究,现在帮你试了一下,其实解决起来很简单了:)<p>关于微软HTML编辑控件单击回车会插入&lt;p>而不是&lt;br>的解决方案</DIV> <p>
<div style='border:1 solid black' contentEditable="true">未经过脚本处理的编辑控件</div>
<script>
//*********************************
//原作者:风云舞,原出处:http://www.lshdic.com/bbs
//本程序需要IE浏览器版本高于IE5.5才能正常调试,另移植到iframe上道理应该相同
//*********************************
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>