커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
웹 개발 개인 공부중 질문이 있습니다.
undefined주차
북마크
이*늘
댓글
5
추천
0
조회수
13
조회수
13
답변 완료


개인 공부를 하고있습니다. ejs 모듈을 이용하여 반복문으로 작성해 글자색이 변하도록 구문을 작성하고 싶은데 html 태그 안에는 작성이 안되는 지 해결하고 싶은데 잘 안됩니다.


파일명은 각각 test.html , test.js 입니다.



변경 전 html 파일입니다.


<% var text = "" %>


 <% colors.forEach( function(once) { %>
 <h2 style= <%text%> >나는 지금 ejs 모듈을 공부하고 있다.</br>그치만 어렵다.</h2>   
<% }) %>
<%text.append("color : once ")%>



변경 전 JS 파일입니다.



// 서버를 생성하고 실행합니다.
http.createServer(function (request, response) {
    // ejsPage.ejs 파일을 읽습니다.
    fs.readFile('test.html','utf8',function (error, data) {
        response.writeHead(200, {'Content-Type': 'text/html'});
        response.write(
            '<head><meta charset="UTF-8"></head>'
        );
        response.end(ejs.render(data, {
            colors: ['red', 'blue']
        }));
    });
}).listen(52274, function() {
    console.log('Server Running at http://127.0.0.1:52274');
});




변경 후 html 파일입니다.


<% colors.forEach( function(color) { %>
      <h2  style = <%= color  %> >나는 지금 ejs 모듈을 공부하고 있다.</br>그치만 어렵다.</h2>
   <% })%>


변경 후 JS 파일입니다.




http.createServer(function (request, response) {
    // ejsPage.ejs 파일을 읽습니다.
    fs.readFile('test.html','utf8',function (error, data) {
        response.writeHead(200, {'Content-Type': 'text/html'});
        response.write(
            '<head><meta charset="UTF-8"></head>'
        );
        response.end(ejs.render(data, {
            colors: [
                {'color': 'red'},
                {'color': 'orange'},
                {'color': 'yellow'},
                {'color': 'green'},
                {'color': 'blue'},
                {'color' : 'navy'},
                {'color': 'purple'},
            ]
        }
        ));
    });
}).listen(52273, function() {
    console.log('Server Running at http://127.0.0.1:52273');
});


취소
 공유
취소
댓글 0
댓글 알림
나의얼굴