jQuery:更改特定的文本颜色 [英] jQuery: Change specific text color
本文介绍了jQuery:更改特定的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法弄清楚.我的网页中有下面的代码,如何使用jQuery将单击此处"更改为蓝色或某种颜色?
I can't seem to figure this out. I have the code below in my web page, how do I change the "Click here" to blue or some color using jQuery?
<td width="30%" valign="top" align="left"
class="td-label-276-7365 td-label-276 labeltext"
id="td-label-field-7365">Flavors [Click here] :
</td>
谢谢.
推荐答案
如果您只想更改单击此处"的颜色,并且绝对必须使用JS,则可以执行以下操作:
If you only want to change the color of "Click here" and you absolutely must use JS, then you can do:
var text = $('td').text();
text = text.replace(/\[Click\shere\]/g, '[<font color="blue">Click here</font>]');
$('td').html(text);
但是更可取的是直接使用html和css进行操作,例如:
But it is more advisable to just do it directly with html and css, like:
<td width="30%" ...>Flavors [<span class="blue">Click here</span>] :</td>
并在您的CSS中:
span.blue {
color: blue;
}
演示:这两种方法都可以在 此处
Demo: Both approaches can be seen here
这篇关于jQuery:更改特定的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文