代码下方的截图显示我的问题。 它只显示一例文字的彩虹。
我怎样才能得到这个代码 来做每个[脑 指定[/脑 文本?
它实际上用于ActionScript, 但它在 Javascript 中也有效, 所以我一直在测试 < a href=" "http://jsfiddle.net" rel = "no follown noreferrer" >http://jsfidd.net
var txt = "This is a [rainbow]test to show that I can[/rainbow] make whatever I want [rainbow]appear as a rainbow[/rainbow] because I am [rainbow]awesome[/rainbow].";
if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
var firstChar = txt.indexOf("[rainbow]") + 9;
var lastChar = txt.indexOf("[/rainbow]");
var RAINBOWTEXT = ;
var i = firstChar;
while (i < lastChar) {
RAINBOWTEXT += txt.charAt(i);
i++
}
var text = RAINBOWTEXT;
var texty = ;
colors = new Array( ff00ff , ff00cc , ff0099 , ff0066 , ff0033 , ff0000 , ff3300 , ff6600 , ff9900 , ffcc00 , ffff00 , ccff00 , 99ff00 , 66ff00 , 33ff00 , 00ff00 , 00ff33 , 00ff66 , 00ff99 , 00ffcc , 00ffff , 00ccff , 0099ff , 0066ff , 0033ff , 0000ff , 3300ff , 6600ff , 9900ff , cc00ff );
var i = 0;
while (i <= text.length) {
var t = text.charAt(i);
if (t != undefined) {
texty += "<font color="#" + colors[i % colors.length] + "">" + t + "</font>";
i++;
}
}
texty = texty.replace("> <", "> <");
var REPLACEME = "[rainbow]" + RAINBOWTEXT + "[/rainbow]";
txt = txt.replace(REPLACEME, texty);
document.write(txt);
}
""https://i.sstatic.net/rZruv.png" alt="此处输入图像描述"/ >