채택완료

스크립트 계절별 이미지

2019-10-09 (수) 15:10:20 4,285

특정일과 시간별 이미지 변경 스크립트로 아래와 같은 스크립트를 사용중입니다.

<script language="JavaScript"> 

var date = new Date(); 
var tYear = <?=date('Y')?>; 
var tMonth = <?=date('m')?>; 
var tDate = <?=date('d')?>; 
var tDay = <?=date('w')?>; 
var tHour = <?=date('h')?>; 
var Today = tYear + "-" + tMonth + "-" + tDate; 
var Holidays = { 
"2014-8-15" : "/img/qna_notice_01.png", 
"2014-9-8" : "/img/qna_notice_01.png", 
"2014-9-9" : "/img/qna_notice_01.png" 
} 

function _time(f, t) { 
return (tHour >= f && tHour < t) ? true : false; 
} 

if(Holidays[Today]) { 
document.write("<img src='" + Holidays[Today] + "' />"); 
} else { 
if((tDay == 6 || tDay == 0) && tHour >= 1) { 
document.write('<img src="/img/qna_notice_01.png">'); 
} else { 
if(_time(0, 11) == true) { 
document.write('<img src="/img/qna_notice_02.png">'); 
} else if(_time(11, 12) == true) { 
document.write('<img src="/img/qna_notice_04.png">'); 
} else if(_time(12, 13) == true) { 
document.write('<img src="/img/qna_notice_03.png">'); 
} else if(_time(13, 18) == true) { 
document.write('<img src="/img/qna_notice_04.png">'); 
} else if(_time(18, 24) == true) { 
document.write('<img src="/qna_notice_02.png">'); 
} 
} 
} 

</script>

위 스크립트를 계절별로

11월~2월

3월 ~6월

7월~ 8월

9월~10월

이렇게 몇월부터 몇월까지 이미지를 자동 변경하면서 보여주려면 어찌 수정해야할까요?
능력자님들 알려주세요..ㅠㅠ

답변 2개 / 댓글 1개

채택된 답변
+20 포인트
2019-10-09 (수) 16:50:31

소스를 다 말씀드리긴 힘들고 저 tMonth 값을 가지고 이용하시면 될거 같습니다. 소스를 잘 모르시니 일단 if 문으로 모든 1~12월에 해당하는 이미지를 넣어보세요

답변에 대한 댓글 1개

네 감사합니다 (__해결하였습니다.
2019-10-09 (수) 16:36:26

제작의뢰로 가보셔야합니다.

답변을 작성하려면 로그인이 필요합니다.