Javascript 如何使用execCommand设置新行?

Javascript 如何使用execCommand设置新行?,javascript,dom,execcommand,Javascript,Dom,Execcommand,我想插入换行符并在新行中设置插入符号位置 我有这个 <!-- editable --> <div> hello </div> 你好 然后我添加一个新行 document.execCommand("insertHtml", false, "world" + "<br> "); document.execCommand(“insertHtml”,false,“world”+””; 但是插入符号不会在之后移动,因此当我键入文本时不会转到

我想插入换行符并在新行中设置插入符号位置

我有这个

<!-- editable -->
<div>
    hello
</div>

你好
然后我添加一个新行

document.execCommand("insertHtml", false, "world" + "<br> ");
document.execCommand(“insertHtml”,false,“world”+”
”;
但是插入符号不会在

之后移动,因此当我键入文本时不会转到新行

如何在新行中设置插入符号的位置,以便在我键入时它显示在下面

实际结果:

helloworld<typedtext>
helloworld
预期结果:

helloworld
<typedtext>
helloworld


在Chrome 15上测试,只需添加一个换行符,它就会在Chrome中移动 像这样的事情

document.execCommand("insertHtml", false, "world");
document.execCommand('insertParagraph',false); 

不久前有人问过这个问题,但希望它对我有用,但在ie9中没有,它在Chrome Canary上对我有用。根据我的经验,至少在Chrome上,只将换行符作为“\n”而不是“\r\n”传递比较好。如果需要插入空行,“\r\n\r\n”将创建并清空,但“\r\n\r\n”将创建
document.execCommand('insertText', true, 'hi\\r\\nworld')