问题描述
有没有办法在textarea中突出显示部分文本?
针对Ex:说文本为Hi @twitter @twitpic现在我只想强调 @twitter和@twitpic ,而不是 Hi 。这需要在飞行中发生。
我不想使用 iframe
在此先感谢
如果没有围绕特定词语包装标签,则无法突出显示它(或者如我所说,至少我不知道如何)。
但如果包装标签没有问题,则应使用regEx。
用于以@开头的字词:
$ b $< code>替换
以及以#开头的单词:
status.replace(/#([^] +)/ g,'< span class =hashtag>#$ 1< / span>');
检查
编辑:您可以替换
var status ='我推送了一些#one #two @three @four';
with
var status = $('#phrase')。text();
Is there a way to highlight a part of text in textarea.
For Ex: Say the text is "Hi @twitter @twitpic" and now I would like to highlight @twitter and @twitpic only and not Hi. This has to happen on the fly.
I dont want to use iframe
Thanks in advance
without wrapping a tag around the specific words, you cannot highlight it (or as i said, at least I have no idea how to).but if there is no problem with wrapping tags, you should use regEx.
for words starting with @ :
replace(/@([^ ]+)/g, '<span class="atsign">@$1</span>');
and for the words starting with # :
status.replace(/#([^ ]+)/g, '<span class="hashtag">#$1</span>');
check this fiddle
EDIT: you can replace
var status = 'I tweeted something #one #two @three @four';
with
var status = $('#phrase').text();
这篇关于如何突出显示textarea中的部分文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!