首页 > 解决方案 > 当在 angular 中使用 innerHTML 属性时,光标插入符号移动到开头

问题描述

在这里,我在 contenteditable div 中使用 innerHTML 属性。问题是每当我尝试编辑内容时,插入符号光标移动到开头并反转整个文本。我应该怎么做才能像正常编辑一样将插入符号移动到结束位置?

我的 HTML 代码:

<div #editor class="editor" 
              style=" max-height: 200px;" 
              [innerHTML]="blogData.description"
              (input)="onChange()"
              (input)="blogData.description=$event.target.innerHTML"
              name="blogData.description"
              contenteditable></div>

在此处输入图像描述

上面的截图显示了差异,实际上我输入的是“this is”,因为光标在开头,内容看起来像这样。提前致谢。

标签: htmlangulartypescriptangular8

解决方案


推荐阅读