我是一个Unicode HTML页面(保存在数据库中),无论如何,我可以通过编程方式更改所有"。"的颜色。和":"文本中的字符(请注意我的HTML内容也包含内联CSS,其中可能包含"。"或":"字符,但我只想更改上述字符的颜色在实际文本中。
我的选择是什么?一种方法是在文本中找到这些字符并将它们放在标签中,以便可以设置样式,任何其他建议? (如果我要使用这种方法,如何区分HTML / CSS字符和文本中的真实字符?)我使用ASP.NET / C#
答案 0 :(得分:4)
尝试将String.prototype.replace()
与RegExp
/\.|:/g
一起使用,返回i
元素并将style
属性设置为特定颜色
var div = document.getElementsByTagName("div")[0];
div.innerHTML = div.innerHTML.replace(/\.|:/g, function(match) {
return "<i style=color:tomato;font-weight:bold>" + match + "</i>"
})
&#13;
<head>
<meta charset="utf-8" />
</head>
<body>
<div>
I've a Unicode HTML page (saved in DB), is there anyway that I can programmatically change color of all "." and ":" characters in text (please pay attention that my HTML content has also inline CSS which may contain "." or ":" characters, but I just want
to change color of the mentioned characters in real text. what are my options? One way can be finding these characters in the text and put them in tag, so that can be styled, any other suggestion? (if I'm going to use this method, how can I distinguish
between HTML/CSS characters and real characters in the text?) I'm using ASP.NET/C#
</div>
</body>
&#13;
答案 1 :(得分:-2)
这是改变HTML语言中任何字符颜色的简单方法
&#34;空间角色&#34;