解决DIV编辑框的回车加的问题

来源:互联网 发布:车牌识别用什么算法 编辑:程序博客网 时间:2024/06/04 18:43
<DIV ID="contentdiv" contentEditable="true" style='border:1 solid black'></DIV>
function contentdiv.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;
       }
}
 
原创粉丝点击