<div 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>
//*********************************
//原作者:风云舞,原出处: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>