最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change color of specific string - Stack Overflow

programmeradmin2浏览0评论

Does anyone know how I could change the color of a specific word if it is typed into a textarea? For instance, if the user types 'hello my friend', it would dynamically change 'hello' to green? Spent a large amount of time on google, and could not find anything very related. Thank you.

Does anyone know how I could change the color of a specific word if it is typed into a textarea? For instance, if the user types 'hello my friend', it would dynamically change 'hello' to green? Spent a large amount of time on google, and could not find anything very related. Thank you.

Share Improve this question edited Apr 14, 2011 at 0:06 Justin Johnson 31.3k7 gold badges66 silver badges89 bronze badges asked Apr 14, 2011 at 0:00 ChrisChris 4613 gold badges9 silver badges16 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 6

textareas aren't designed to be selectively colored.

You can't do it in a textarea field because its only content can be text, not HTML. You'll have to use an editable DIV or something, and then replace the word in string with <span>word</span> and apply a CSS class to the SPAN.

In textarea you can't. But there is posibility of "editable div". See http://codemirror/

The HTML specs don't allow different fonts within the same textarea element. You can't do this.

However, you can make an editor with JS that will do pretty much what you want. These things tend to be pretty big projects, so you probably want something premade. There is a list here.

发布评论

评论列表(0)

  1. 暂无评论