Javascript颜色显示

时间:2014-12-31 02:10:27

标签: javascript html node.js

我正在尝试使用node.js从js文件创建HTML文件!我的问题是为什么颜色不显示在html文件中。我为十六进制值创建了字符串,但在html文件中没有显示颜色。

var format;
function RND() {
var hex = ((Math.floor(Math.random()*0xffffff)+1)).toString(16);
while (hex.length < 6) hex = "0" + hex;
 return "#"+hex;
}
console.log("<html><head>");
console.log("<meta charset=\"UTF-8\">");
console.log("<title>Ten Random Colors</title>");
console.log("</head>");
console.log("<body>");
console.log("<ul>");
for(var i = 0; i < 100; i++){
var color = RND();
//console.log(color);
format="<li style =\""+color+"\">"+color+"</li>";
console.log(format);
}
console.log("</ul>");
console.log("</body>");
console.log("</html>");

1 个答案:

答案 0 :(得分:3)

您错过了CSS密钥

更改此

format="<li style =\""+color+"\">"+color+"</li>";

到这个

format = "<li style =\"color : " + color + "\">" + color + "</li>";

你拥有的东西会给你

<li style="#ffffff">#ffffff</li>

无效