我有以下 HTML 代码:
<p>
<label>* Name</label>
</p>
<p>
<label>* Last Name</label>
</p>
<p>
<label>Mascot Name</label>
</p>
是否可以使用 jQuery 将颜色仅更改为字符 *
?
我尝试使用函数 find()
但我重复了标签上的所有字符。
最佳答案
如果您坚持使用脚本化解决方案:
$("p > label:contains('*')").each(function () {
$(this).html($(this).html().replace("*", "<span class='red'>*</span>"));
});
关于jquery - 改变角色的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8881171/