【发布时间】:2019-05-26 21:58:34
【问题描述】:
我有 textarea 表单,当我在其中输入超过特定数量的字符(超过 2200 个字符)时,我希望在此之后的所有文本都会突出显示。
这是我的 html 代码:
<div class="form-group">
<textarea type="text"
id="textAreaScroll"
formControlName="text"
placeholder="متن ..."
(keyup)="postLengthCheck('text')">
</textarea>
</div>
这是我的打字稿代码:
postLengthCheck(input) {
if (input === 'text') {
if (this.createPostForm.controls['text'].value !== null) {
this.postLength = this.createPostForm.controls['text'].value.length;
this.validTextLength = 2200 - this.postLength;
if (this.postLength > 2200) {
this.x = this.createPostForm.controls['text'].value.substring(2200, this.postLength);
console.log(this.x);
this.match = new RegExp(this.x, 'ig');
this.markText = '<mark>' + this.x + '<\/mark>';
this.replaced = this.createPostForm.controls['text'].value.replace(this.match, this.markText);
this.createPostForm.controls['text'].value = this.replaced;
}
}
}
}
在我的css 中,我定义mark 类如下:
mark {
border-radius: 3px;
color: transparent;
background-color: #b1d5e5;
}
但这不起作用。我该如何解决这个问题?
【问题讨论】:
标签: angular textarea form-control