gpt4 book ai didi

angular - 在 Angular4+ 中插入插入符号

转载 作者:行者123 更新时间:2023-12-02 03:33:02 25 4
gpt4 key购买 nike

在将插入符号插入特定光标位置的文本区域时,我完全陷入了 Angular 项目的困境。我尝试将标签/文本动态插入到选定光标位置的文本区域。

你能帮我吗?

谢谢,斯里普里亚 J

最佳答案

如果你想将光标聚焦在特定位置,你需要使用selectionStart原生元素

var startPos=this.r.nativeElement.selectionStart;
this.r.nativeElement.focus();

然后您需要将先前的值与当前值连接

this.r.nativeElement.value=this.r.nativeElement.value.substr(0,this.r.nativeElement.selectionStart)+e+this.r.nativeElement.value.substr(this.r.nativeElement.selectionStart,this.r.nativeElement.value.length);

查看此处的示例:https://stackblitz.com/edit/angular-hn8unq

关于angular - 在 Angular4+ 中插入插入符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51257183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com