JS Reference

JS by Category JS by Alphabet

JavaScript

JS Array JS Boolean JS Classes JS Date JS Error JS Global JS JSON JS Math JS Number JS Operators JS RegExp JS Statements JS String

Window

Window Object Window Console Window History Window Location Window Navigator Window Screen

HTML DOM

DOM Document DOM Element DOM Attributes DOM Events DOM Event Objects DOM HTMLCollection DOM Style
alignContent alignItems alignSelf animation animationDelay animationDirection animationDuration animationFillMode animationIterationCount animationName animationTimingFunction animationPlayState background backgroundAttachment backgroundColor backgroundImage backgroundPosition backgroundRepeat backgroundClip backgroundOrigin backgroundSize backfaceVisibility border borderBottom borderBottomColor borderBottomLeftRadius borderBottomRightRadius borderBottomStyle borderBottomWidth borderCollapse borderColor borderImage borderImageOutset borderImageRepeat borderImageSlice borderImageSource borderImageWidth borderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRadius borderRight borderRightColor borderRightStyle borderRightWidth borderSpacing borderStyle borderTop borderTopColor borderTopLeftRadius borderTopRightRadius borderTopStyle borderTopWidth borderWidth bottom boxShadow boxSizing captionSide caretColor clear clip color columnCount columnFill columnGap columnRule columnRuleColor columnRuleStyle columnRuleWidth columns columnSpan columnWidth counterIncrement counterReset cursor direction display emptyCells filter flex flexBasis flexDirection flexFlow flexGrow flexShrink flexWrap cssFloat font fontFamily fontSize fontStyle fontVariant fontWeight fontSizeAdjust height isolation justifyContent left letterSpacing lineHeight listStyle listStyleImage listStylePosition listStyleType margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth objectFit objectPosition opacity order orphans outline outlineColor outlineOffset outlineStyle outlineWidth overflow overflowX overflowY padding paddingBottom paddingLeft paddingRight paddingTop pageBreakAfter pageBreakBefore pageBreakInside perspective perspectiveOrigin position quotes resize right scrollBehavior tableLayout tabSize textAlign textAlignLast textDecoration textDecorationColor textDecorationLine textDecorationStyle textIndent textOverflow textShadow textTransform top transform transformOrigin transformStyle transition transitionProperty transitionDuration transitionTimingFunction transitionDelay unicodeBidi userSelect verticalAlign visibility width wordBreak wordSpacing wordWrap widows zIndex

Web APIs

API Console API Fullscreen API Geolocation API History API MediaQueryList API Storage

HTML Objects

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

Other References

CSSStyleDeclaration JS Conversion


창 setTimeout()

인사말을 5초 동안 기다립니다.

const myTimeout = setTimeout(myGreeting, 5000);

myGreeting이 실행되지 않도록 하려면 clearTimeout(myTimeout)을 사용합니다.

const myTimeout = setTimeout(myGreeting, 5000);

function myStopFunction() {
  clearTimeout(myTimeout);
}

아래에 더 많은 예가 있습니다.


정의 및 사용

setTimeout()메서드는 몇 밀리초 후에 함수를 호출합니다.

1초 = 1000밀리초.

노트

setTimeout()번만 실행됩니다.

반복 실행이 필요한 경우 setInterval()대신 사용하십시오.

clearTimeout()이 메서드를 사용 하여 기능이 시작되지 않도록 합니다.

시간 초과를 지우려면 setTimeout()에서 반환된 ID 를 사용합니다.

myTimeout = setTimeout(function, milliseconds);

그런 다음 clearTimeout()을 호출하여 실행을 중지할 수 있습니다.

clearTimeout(myTimeout);

또한보십시오:

clearTimeout() 메서드

setInterval() 메서드

clearInterval() 메서드


통사론

setTimeout(function, milliseconds, param1, param2, ...)

매개변수

Parameter Description
function Required.
The function to execute.
milliseconds Optional.
Number of milliseconds to wait before executing.
Default value is 0.
param1,
param2,
...
Optional.
Parameters to pass to the function.
Not supported in IE9 and earlier.

반환 값

유형 설명
번호타이머의 ID입니다.
이 ID를 clearTimeout(id)과 함께 사용하여 타이머를 취소합니다.


더 많은 예

3초(3000밀리초) 후에 경고 상자 표시:

let timeout;

function myFunction() {
  timeout = setTimeout(alertFunc, 3000);
}

function alertFunc() {
  alert("Hello!");
}

시간 제한 텍스트 표시:

let x = document.getElementById("txt");
setTimeout(function(){ x.value = "2 seconds" }, 2000);
setTimeout(function(){ x.value = "4 seconds" }, 4000);
setTimeout(function(){ x.value = "6 seconds" }, 6000);

새 창을 열고 3초(3000밀리초) 후에 창을 닫습니다.

const myWindow = window.open("", "", "width=200, height=100");
setTimeout(function() {myWindow.close()}, 3000);

영원히 카운트 - 그러나 카운트를 중지할 수 있는 기능:

function startCount()
function stopCount()

타이밍 이벤트로 생성된 시계:

function startTime() {
  const date = new Date();
  document.getElementById("txt").innerHTML = date.toLocaleTimeString();
  setTimeout(function() {startTime()}, 1000);
}

함수에 매개변수 전달(IE9 및 이전 버전에서는 작동하지 않음):

setTimeout(myFunc, 2000, "param1", "param2");

그러나 익명 기능을 사용하면 모든 브라우저에서 작동합니다.

setTimeout(function() {myFunc("param1", "param2")}, 2000);

브라우저 지원

setTimeout() 모든 브라우저에서 지원됩니다:

Chrome IE Edge Firefox Safari Opera
Yes Yes Yes Yes Yes Yes