Closed. This question needs to be more focused。它当前不接受答案。
想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
2年前关闭。
我在网站标题上有一个标题,它将以给定的时间间隔显示(标题在数组中声明)。
我想更改字符串集中特定单词的颜色。喜欢,想要更改Lucky,Vasudeva,Krishna的颜色。
提前致谢!
想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
2年前关闭。
我在网站标题上有一个标题,它将以给定的时间间隔显示(标题在数组中声明)。
我想更改字符串集中特定单词的颜色。喜欢,想要更改Lucky,Vasudeva,Krishna的颜色。
var caption = document.getElementById('caption');
var text = ['Ajay garidipuri lucky ', 'Vasudeva Vijay', 'Mude krishna unlucky '];
function display(i) {
if (i >= text.length) {
i = 0;
}
caption.innerHTML = text[i];
setTimeout(function() {
display(i + 1)
}, 6000)
}
display(0)
.content-video h1 {
font-size: 52px;
margin-bottom: 6px;
text-align: center;
color: white;
padding-top: 25%;
padding-left: 0%;
padding-right: 3%;
font-weight: bold;
text-shadow: 2px 2px 4px #000000;
}
#caption {
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
}
<div class="content-video">
<h1><span id="caption"> </span></h1>
</div>
提前致谢!
最佳答案
尽我所知,现在可以更改字符串中特定单词的样式,除非您用自己的标签(如或)包装您的单词,并为该标签指定所需颜色的样式/类。
这意味着您无需执行以下操作:caption.innerHTML = text[i];
您将需要在内部附加一个内部<span>
或其他标签。
因此,您的最终HTML应该如下所示:
<span id="caption"> Ajay garidipuri <span class='lucyColor'>lucky</span></span>
关于javascript - 如何将颜色更改为数组字符串中的特定单词? :Javascript/jQuery ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52691415/