更改字符的颜色 [英] Change color of a character

查看:148
本文介绍了更改字符的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML代码:

I have the following HTML code:

<p>
<label>* Name</label>
</p>
<p>
<label>* Last Name</label>
</p>
<p>
<label>Mascot Name</label>
</p>

可以将颜色更改为字符 * 与jQuery?
我尝试了函数 find(),但我重复标签上的所有字符。

Is it possible to change the color only to the character * with jQuery? I tried with the function find() but I repeat all the characters on the label.

推荐答案

如果您坚持使用脚本解决方案:

If you insist on a scripted solution:

$("p > label:contains('*')").each(function () {
    $(this).html($(this).html().replace("*", "<span class='red'>*</span>"));
});

Demo。

这篇关于更改字符的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆