-1

我正在为我玩的一款游戏制作指南,我想知道是否有一种方法可以将多次输入的特定单词斜体化,而无需<i>一遍</i>又一遍地输入。我尝试查找如何,但要么我是盲人,要么我找不到。

4

1 回答 1

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>

于 2015-02-24T00:51:22.007 回答