Multicolor Text Highlighting in a Textarea or Text Input

后端 未结 4 930
情书的邮戳
情书的邮戳 2020-11-27 05:38

I\'d like to set text in a textarea or text input using different colors (one or the other is fine, I don\'t need both). Think of something like simple syntax highlighting.

4条回答
  •  轮回少年
    2020-11-27 05:58

    No, you can't do this in a textarea or text input. Any CSS text-related property will affect the whole text within the the textarea/input. You'll need an editable element or document to achieve syntax highlighting. Example (works in all recent browsers; the last major browser not to support contenteditable was Firefox 2.0):

    
      var foo = "bar";
    

提交回复
热议问题