[英]How can I get the text right before the cursor position starting from a contenteditable area
I have a contenteditable area and it may have something like我有一个 contenteditable 区域,它可能有类似的东西
Hello @abc @my| it was nice to see you
The |的| is my cursor, and want to get the text from the '@' symbol nearest to the cursor to the cursor position, so in this case, I want to get '@my'.
是我的光标,并且想要从离光标最近的“@”符号到光标位置获取文本,因此在这种情况下,我想要获取“@my”。 I have completely no idea how can I get the text backward from a position.
我完全不知道如何从一个位置向后获取文本。
given the caret position as caretpos, and value of textbox as text给定插入符号位置作为插入符号,文本框的值作为文本
var result = /\S+@/.exec(text.slice(0, caretpos));
var lastpos = result.length>0 ? result.lenth - 1:0;
var lastWord = result ? result[lastpos] : null;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.