我想插入一个换行符,并在新行中设置插入符号的位置。
我有这个
<!-- editable -->
<div>
hello
</div>
然后添加新行
document.execCommand("insertHtml", false, "world" + "<br> ");
但是插入符号没有移动到<br>
之后,所以当我输入文本时,文本不会转到新行。
我如何设置插入符号的位置在新的行,所以当我键入它在下面?
实际结果:helloworld<typedtext>
预期结果:
helloworld
<typedtext>
jsFiddle
示例Chrome 15测试
只需添加一个换行符,它将在chrome中移动比如像这样的
document.execCommand("insertHtml", false, "world");
document.execCommand('insertParagraph',false);
刚才有人问这个问题,但希望它能帮助到别人
document.execCommand('insertText', true, 'hi\r\nworld')