注意:我已阅读https://meta.stackexchange.com/questions/128548/what-stack-overflow-is-not/129362#129362
它说“尝试自己编写代码,并在遇到问题时发布您尝试过的内容。” 这就是我在这里所做的。
原始PHP代码:
$text = "Hello world, I am rainbow text!";
$texty = '';
$colors = 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');
$i = 0;
$textlength = strlen($text);
while($i<=$textlength){
foreach($colors as $key=>$value){
if (isset($text[$i])) {
$texty .= "<font color=\"#".$value."\">".$text[$i]."</font>";
}
$i++;
}
$texty = str_replace("> <","> <",$texty);
echo $texty;
}
我把它扼杀为:
var text = "Hello world, I am rainbow text!";
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;
var textlength = text.length;
var key = '';
var value = '';
while(i <= textlength){
for each(colors as key=>value){
if (text[i] != undefined) {
texty .= "<font color=\"#" + value + "\">" + text[i] + "</font>";
}
i++;
}
texty.replace("> <","> <");
//document.write(texty);
}
我一直在将其作为 Javascript 进行测试,这就是为什么我在代码中添加了 document.write 注释。但是,我仍然无法让它工作。我讨厌这么含糊,但是...有人可以告诉我我在哪里搞砸了吗?