【发布时间】:2018-10-11 15:47:08
【问题描述】:
当我从搜索移动到文本区域中存在大文本的所需单词时,我已经有了这个单词的第一个索引和最后一个索引。有了这个,我会 setSelectionRange (firstIndex, lastIndex) 和 focus ()。
但问题是自动滚动到这个词不起作用,你需要手动滚动才能看到突出显示的词。如何解决这个问题?
ngOnInit() {
const subscription = this.pageService.subject.subscribe(
r => {
setTimeout(() => {
this.textareaNovel.nativeElement.focus();
const firstIndex = this.pageService.allIndex[this.pageService.indexOfOne];
const lastIndex = firstIndex + this.pageService.inputSearchText.length;
this.textareaNovel.nativeElement.setSelectionRange(firstIndex,lastIndex);
}, 100);
},
e => console.error(e),
() => console.info("completed")
);
}
【问题讨论】:
标签: javascript angular textarea