【发布时间】:2017-11-19 18:48:13
【问题描述】:
我有文本,文本中的某些单词带有空格,例如 我喜欢 R O S E S 和树木。空格是在此功能的帮助下生成的
this.text = this.text.replace(new RegExp(this.words.join('|'), 'g'), function insertSpaces(x) {
return x.split('').join(' ');
}); };
文字是I like roses and trees,单词是ROSES,我想让点击单词ROSES成为可能在字母之间,如果我点击那里会出现“-”而不是空格。因此,如果我在 R 和 O 之间单击,如果我在 R 和 O 之间单击,则会出现 RO SES 而不是 ROSES strong>O 和 S,出现 R OS ES 而不是 ROSES 等等……Angular2 可以吗?
更新
我现在试试这段代码
getCaretPos(oField: any, a: any) {
if (oField.selectionStart || oField.selectionStart === '0') {
this.caretPos = oField.selectionStart;
//assign char at choosed position to new variable
a = this.text.charAt(this.caretPos);
//replace this char with "-"
this.text.replace(a, '-');
}
}
}
【问题讨论】:
标签: javascript angular typescript input