admin管理员组文章数量:1327991
I want to insert a line break and set the caret position in the new line.
I have this
<!-- editable -->
<div>
hello
</div>
Then I add a new line
document.execCommand("insertHtml", false, "world" + "<br> ");
But the caret is not moved after the <br>
, so when I type the text doesn't go to the new line.
How can I set the caret position in the new line so when I type it goes bellow?
Actual result:
helloworld<typedtext>
Expected result:
helloworld
<typedtext>
Example on jsFiddle
Tested on Chrome 15
I want to insert a line break and set the caret position in the new line.
I have this
<!-- editable -->
<div>
hello
</div>
Then I add a new line
document.execCommand("insertHtml", false, "world" + "<br> ");
But the caret is not moved after the <br>
, so when I type the text doesn't go to the new line.
How can I set the caret position in the new line so when I type it goes bellow?
Actual result:
helloworld<typedtext>
Expected result:
helloworld
<typedtext>
Example on jsFiddle
Tested on Chrome 15
Share Improve this question edited Aug 14, 2011 at 20:44 BrunoLM asked Aug 14, 2011 at 15:54 BrunoLMBrunoLM 100k86 gold badges309 silver badges461 bronze badges 2- that's working for me but no in ie9, jsfiddle/BhZzu – Eric Fortis Commented Aug 14, 2011 at 16:08
- It works for me on Chrome Canary. – pimvdb Commented Aug 14, 2011 at 16:43
2 Answers
Reset to default 4just add a line break and it will move it in chrome so some thing like this
document.execCommand("insertHtml", false, "world");
document.execCommand('insertParagraph',false);
Question was asked a while ago but hope it helps someone anyway
document.execCommand('insertText', true, 'hi\\r\\nworld')
本文标签: javascriptHow to use execCommand to set a new lineStack Overflow
版权声明:本文标题:javascript - How to use execCommand to set a new line? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742235821a2438060.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论