2015-10-03 16 views
3

我有一個Unicode HTML頁面(保存在數據庫中),有無論如何,我可以通過編程方式更改所有的顏色「。」。和「:」中的字符(請注意,我的HTML內容也包含可能包含「。」或「:」字符的內聯CSS,但我只是想改變所提到的字符的真實文本的顏色。我的選擇是什麼?一種方法可以在文本中找到這些字符並將它們放在標記中,以便可以設置樣式,還有其他建議嗎?(如果我要使用此方法,我如何區分HTML/CSS人物和真實人物的文字?)我使用ASP.NET/C#更改HTML中特殊字符的顏色

+0

可以包括'html','css'在問題的簡單方法是什麼? – guest271314

+1

如果你想只有asp.net解決方案不應該刪除最小的JavaScript標籤?對不起,如果我錯了 – Jesse

+0

我認爲基於JS/CSS的解決方案會更好/更容易實現,我提到ASP.NET只是爲了明確我的編程方法。任何可以解決問題的解決方案都將受到高度的歡迎! –

回答

4

嘗試利用String.prototype.replace()RegExp/\.|:/g,返回與style屬性i元素設置爲特定顏色

var div = document.getElementsByTagName("div")[0]; 
 
div.innerHTML = div.innerHTML.replace(/\.|:/g, function(match) { 
 
    return "<i style=color:tomato;font-weight:bold>" + match + "</i>" 
 
})
<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>

-1

這是更改任何字符的顏色在HTML語言

「空間性」

+0

你的答案是什麼? –

+0

* Pushpendra