给句子上色
本文关键字:句子 | 更新日期: 2023-09-27 18:04:45
如何为句子中的特定字符串设置颜色以与其他字符串区分?
我试过用粗体
"<b>" + myValue + "<b>"
我想如果我用彩色格式显示它会很好。如何做到这一点
您可以使用内联样式标签设置特定句子的颜色:
对于标题:
<h1 style="color:blue">This is a Blue Heading</h1>
段落:
<p style="color:red">This is a red Paragraph</p>
或任何你想要的地方:
<span style="color:blue">Some blue text</span>
即使在另一个句子中:
<p>This is a boring paragraph <span style="color:green">with some amazing green text!</span> boring again...</p>
使用javascript变量
<script>
var string = "This is a string";
document.getElementById("myText").style.color = "red";
document.getElementById("myText").innerHTML=string;
</script>
<span id="myText"></span>