<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;
}
}
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;
}
}
本文介绍了一种使用JavaScript实现的自定义换行功能,该功能通过监听键盘事件并在用户按下回车键时插入特定字符来模拟换行效果。文章详细解释了如何处理IE浏览器中的文本选择问题,并提供了具体的实现代码。

1054

被折叠的 条评论
为什么被折叠?



