我正在为我玩的一款游戏制作指南,并且我想知道是否有一种方法可以将多次键入的特定单词斜体化而无需键入<i>
和</i>
一遍又一遍地。我试着查看如何,但要么我是盲人,要么我找不到。
答案 0 :(得分:0)
必须使用javascript完成。干得好...
var wordAr = ["quick", "fox",];
var theText = document.getElementById("theText").innerHTML;
for (i in wordAr) {
theText = theText.replace(new RegExp(wordAr[i], 'g'), '<i>'+wordAr[i]+'</i>');
}
document.getElementById("theText").innerHTML = theText;
<div id="theText">
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
</div>