是否可以更改文本框中单词的颜色?

时间:2022-11-21 15:55:33

I have a regular texbox control. I need to highlight some words with a red color. Is it any possible to do with JavaScript (jquery or anything else)?

我有一个常规的texbox控件。我需要用红色突出显示一些单词。是否可以使用JavaScript(jquery或其他任何东西)?

4 个解决方案

#1


Most rich text javascript editors use an iframe with designMode='on' since that yields the best cross browser results:

大多数富文本javascript编辑器使用iframe与designMode ='on',因为这会产生最佳的跨浏览器结果:

<iframe ID="rtbox"></iframe>

To make the iframe editable and insert rich text via Javascript you can use the following sample code:

要使iframe可编辑并通过Javascript插入富文本,您可以使用以下示例代码:

var rtbox = document.getElementById('rtbox');
var doc = rtbox.document ? rtbox.document : rtbox.contentDocument;
doc.designMode = 'on';
doc.body.innerHTML = 'one <span style="color:red">red</span> word';

#2


No, you can't do that. Your only way would be to use a rich text editor component like FCKEditor or similar.

不,你做不到。您唯一的方法是使用像FCKEditor或类似的富文本编辑器组件。

#3


No you cannot use different styles in a standard <textarea>.

不,你不能在标准

#4


I recommend using TinyMCE for a rich text editor.

我建议使用TinyMCE作为富文本编辑器。

And no, what you say is not possible on a normat textarea.

不,你说的在normat textarea上是不可能的。

#1


Most rich text javascript editors use an iframe with designMode='on' since that yields the best cross browser results:

大多数富文本javascript编辑器使用iframe与designMode ='on',因为这会产生最佳的跨浏览器结果:

<iframe ID="rtbox"></iframe>

To make the iframe editable and insert rich text via Javascript you can use the following sample code:

要使iframe可编辑并通过Javascript插入富文本,您可以使用以下示例代码:

var rtbox = document.getElementById('rtbox');
var doc = rtbox.document ? rtbox.document : rtbox.contentDocument;
doc.designMode = 'on';
doc.body.innerHTML = 'one <span style="color:red">red</span> word';

#2


No, you can't do that. Your only way would be to use a rich text editor component like FCKEditor or similar.

不,你做不到。您唯一的方法是使用像FCKEditor或类似的富文本编辑器组件。

#3


No you cannot use different styles in a standard <textarea>.

不,你不能在标准

#4


I recommend using TinyMCE for a rich text editor.

我建议使用TinyMCE作为富文本编辑器。

And no, what you say is not possible on a normat textarea.

不,你说的在normat textarea上是不可能的。