node.js를 사용하여 js 파일에서 HTML 파일을 만들려고합니다! 내 질문은 html 파일에 색상이 표시되지 않는 이유입니다. 16 진수 값에 대한 문자열을 만들었지 만 html 파일에서 색상이 표시되지 않습니다. 당신은 CSS 키를 놓치고자바 스크립트 색상 표시
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>");
콘솔에 색상이 표시되기를 기대하지 않으 셨습니까? – adeneo
아니요. node.js를 사용하면 출력을 HTML 문서로 보낼 수 있으므로 기본적으로 HTML 문서를 만들기 위해 모든 것을 따옴표로 출력합니다. – James
잘 작동하지만 10이 아닌 100 개의 색상을 출력합니다. – meagar