开发者

Change color of specific string

开发者 https://www.devze.com 2023-02-25 15:02 出处:网络
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? Sp

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.


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.net/


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.


Change color of specific string

0

精彩评论

暂无评论...
验证码 换一张
取 消