如何突出显示文本区域中的第一行 [英] How to highlight the first line in the text area
本文介绍了如何突出显示文本区域中的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以指导我如何突出显示文本区域的第一行。
谢谢。
Can some one guide me how to highlight first line of the text area.
Thanks.
推荐答案
这是通过调用setSelectionRange
来完成的:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange [ ^ ]。
由于一些错误,解决方案1将无法正常工作,但有些想法是正确的:首先,您需要找到第一行的结尾,或者通过拆分,或者更简单,通过搜索最近的结束行位置: https://developer.mozilla.org/ en-US / docs / Web / JavaScript / Reference / Global_Objects / String / search [ ^ ]。
然后调用
This is done by a call tosetSelectionRange
:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange[^].
Solution 1 won't work due to some bugs, but some ideas are correct: first, you need to find out the end of the first line, either by splitting, or, simpler, by the search for nearest end-of-line position: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search[^].
Then call
myTextArea.setSelectionRange(0, endOfFirstLine);
< br $>
这篇关于如何突出显示文本区域中的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文