자바 스크립트는 CSS를 사용하여 스타일을 어떻게 변경합니까?CSS를 사용하여 JavaScript 출력 스타일 지정하기
(또는 다른 대안)
나는 타이머가 0에 도달하면 창을 닫습니다 스크립트를 필요로하지만 발생하지 않습니다. 무엇이 잘못 되었나요?
카운트 다운을 진행률 막대와 통합하는 방법이 있습니까?
<span id="countdown"></span>
<script type="text/javascript">
// set the date we're counting down to
var target_date = new Date().getTime();
var delay = 10;
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("countdown");
// update the tag with id "countdown" every 1 second
setInterval(function() {
// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (current_date - target_date)/1000;
var a = (delay - seconds_left);
// do some time calculations
minutes = parseInt(a/60);
seconds = parseInt(a % 60);
// format countdown string + set tag value
countdown.innerHTML = minutes + "m: " + seconds + "s";
if (seconds_left > delay) {
setTimeout(action(), 10);
}
}, 1000);
var action = function() {
close();
}
</script>
당신의 스타일을 CSS를 사용하면 다른 요소와 마찬가지로 사용할 수 있습니다. 다음은 예제입니다 : http://jsfiddle.net/k9mN5/ – APAD1
100 % 확실하지는 않지만'countdown' 요소에서'.style' 객체를 찾고 있다고 생각합니다. 'countdown.style.display = 'none''와 같은 일을하십시오. – freefaller
@freefaller 인라인 스타일 시트를 사용하지 마십시오. 사용 된 스타일을 포함하는 클래스 이름을 설정하면 코드가 훨씬 더 유연 해집니다. 예 :'countdown.classList.add ('hide');' – feeela