简体   繁体   English

HTML文本区域内的样式文本

[英]Style text inside an HTML textarea

My problem is that I have textarea and want to find a specified string and mark all of its occurences (something similar to what regex101.com does with regex matches). 我的问题是我有textarea,想找到一个指定的字符串并标记所有出现的字符串(类似于regex101.com对regex匹配所做的操作)。

This leads me to a more general question (see my question title) and I would like to learn if the following can be applied to parts of text inside a textarea: 这使我想到了一个更笼统的问题(请参阅我的问题标题),我想了解以下内容是否可以应用于文本区域内的部分文本:

  • change font color 更改字体颜色
  • change background color 改变背景颜色
  • change font style (bold, italic) 更改字体样式(粗体,斜体)
  • change font size 更改字体大小

Should I use something which already exists (like codemirror )? 我应该使用已经存在的东西(例如codemirror )吗?

I would also appreciate it if someone could explain the idea behind this (for example regex101.com has a textarea but also uses some span elements to highlight the matches) 如果有人可以解释其背后的想法,我也将不胜感激(例如regex101.com具有textarea,但也使用一些span元素来突出显示匹配项)

Have you tried doing something like: 您是否尝试过执行以下操作:

var textArea = document.getElementById("textArea");
textArea.style.color = 'Red';
textArea.style.backgroundColor = 'Black';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM