jQuery/JavaScript-高亮显示输入或文本区域中的一部分文本 [英] JQuery/JavaScript - highlight a part of text from input or textarea
本文介绍了jQuery/JavaScript-高亮显示输入或文本区域中的一部分文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Possible Duplicate:
How to highlight a part part of an Input text field in HTML using Javascript or JQuery
有人知道如何突出显示input[type=text]
或textarea
中的某些文本吗?
有可能吗?
Does anyone know how to highlight some text in input[type=text]
or textarea
?
Is it possible?
推荐答案
您必须在textarea
后面放置一个div
,然后根据其文本设置样式.
注释:
You have to place a div
behind your textarea
and then style it according to it's text.
Notes:
- 将
textarea
background-color
设置为透明以查看您的highlighter
颜色. - 您的
highlighter
必须具有与textarea
相同的样式和文本内容,才能将span
放置在正确的位置. - 将
highlighter
文本设置为与背景相同的颜色,否则您会看到<b>
效果,与span
相同.
- Set your
textarea
background-color
to transparent to see yourhighlighter
color. - Your
highlighter
have to be the same style and text content of yourtextarea
to put thespan
on the right place. - Set your
highlighter
text to the same color of it's background or you'll see a<b>
effect, the same for thespan
.
html :
<div class="highlighter">some text <span>highlighted</span> some text</div>
<textarea>some text highlighted some text</textarea>
css :
.highlighter, textarea {
width: 400px;
height: 300px;
font-size: 10pt;
font-family: 'verdana';
}
.highlighter {
position: absolute;
padding: 1px;
margin-left: 1px;
color: white;
}
.highlighter span {
background: red;
color: red;
}
textarea {
position: relative;
background-color: transparent;
}
这篇关于jQuery/JavaScript-高亮显示输入或文本区域中的一部分文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文