我想在一个contenteditable div中插入一些html.
在编辑内容时,用户点击一个图标,一个对话框弹出,然后他进入网址&在对话框中锚定文本.这导致可编辑的div失去焦点,链接插入div的开头,而不是插入符号.我尝试了很多东西但是我被卡住了.
我的可编辑内容div的“rte”id
对话框中按钮的“link_add”id
- $('#link_add').click(function (e)
- {
- $('#rte').focus();
- document.execCommand('insertHTML',false,'html content test');
- close_modal ();
- e.preventDefault();
- });
我还尝试了set execcommand just for a div的解决方案,使用:
- function execCommandOnElement(el,commandName,value)
但这会清空div并粘贴新内容.