ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺪﻨﺑ ﻥﺎﻣﺯ ﯼﺎﻫﺩﺍﺪﯾﻭﺭ


فهرست مطالب

    نمایش فهرست مطالب


.ﺩﺮﮐ ﺍﺮﺟﺍ ﯽﻧﺎﻣﺯ ﯼﺎﻫ ﻩﺯﺎﺑ ﺭﺩ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

.ﯼﺪﻨﺑ ﻥﺎﻣﺯ ﯼﺎﻫﺩﺍﺪﯾﻭﺭ ﺪﻨﯾﻮﮔ ﯽﻣ ﻦﯾﺍ ﻪﺑ

1
2
3
4
5
6
7
8
9
10
11
12

ﯼﺪﻨﺑ ﻥﺎﻣﺯ ﯼﺎﻫﺩﺍﺪﯾﻭﺭ

.ﺪﻫﺩ ﯽﻣ ﺺﺨﺸﻣ ﯽﻧﺎﻣﺯ ﯼﺎﻫ ﻩﺯﺎﺑ ﺭﺩ ﺍﺭ ﺪﮐ ﯼﺍﺮﺟﺍ ﻥﺎﮑﻣﺍ window

.ﺪﻨﻣﺎﻧ ﯽﻣ ﯼﺪﻨﺑ ﻥﺎﻣﺯ ﯼﺎﻫﺩﺍﺪﯾﻭﺭ ﺍﺭ ﯽﻧﺎﻣﺯ ﯼﺎﻫ ﻩﺯﺎﺑ ﻦﯾﺍ

:ﺯﺍ ﺪﻨﺗﺭﺎﺒﻋ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺎﺑ ﻩﺩﺎﻔﺘﺳﺍ ﯼﺍﺮﺑ ﯼﺪﯿﻠﮐ ﺵﻭﺭ ﻭﺩ

  • setTimeout(function, milliseconds)
    ﺪﻨﮐ ﯽ

  • setInterval(ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ ،ﻊﺑﺎﺗ)
    ﺪﻨﻧﺎﻤﻫ set

setTimeout()setInterval


.()setTimeout ﺪﺘﻣ

window.setTimeout(function, milliseconds);

.ﺖﺷﻮﻧ ﻩﺮﺠﻨﭘ ﺪﻧﻮﺸﯿﭘ ﻥﻭﺪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ window.setTimeout()

.ﺩﻮﺷ ﺍﺮﺟﺍ ﺪﯾﺎﺑ ﻪﮐ ﺖﺳﺍ ﯽﻌﺑﺎﺗ ﺮﺘﻣﺍﺭﺎﭘ ﻦﯿﻟﻭﺍ

.ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﺍﺮﺟﺍ ﺯﺍ ﻞﺒﻗ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ ﺩﺍﺪﻌﺗ ﻡﻭﺩ ﺮﺘﻣﺍﺭﺎﭘ

ﻝﺎﺜﻣ

:ﺪﻫﺩ ﯽﻣ ﺭﺍﺪﺸﻫ ﺍﺭ "Hello" ﻪﺤﻔﺻ ﻭ ﺪﯿﻨﮐ ﺮﺒﺻ ﻪﯿﻧﺎﺛ 3 .ﺪﯿﻨﮐ ﮏﯿﻠﮐ ﻪﻤﮐﺩ ﮏﯾ ﯼﻭﺭ

<button onclick="setTimeout(myFunction, 3000)">Try it</button>

    <script>
function myFunction() {
  alert('Hello');
    }
</script>

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Timing</h2>

<p>Click "Try it". Wait 3 seconds, and the page will alert "Hello".</p>

<button onclick="setTimeout(myFunction, 3000);">Try it</button>

<script>
function myFunction() {
  alert('Hello');
}
</script>

</body>
</html>


؟ﻢﯿﻨﮐ ﻒﻗﻮﺘﻣ ﺍﺭ ﻡﺍﺪﻋﺍ ﻪﻧﻮﮕﭼ

ﺪﻨﮐ ﯽﻣ ﻒﻗﻮﺘﻣ ﺍﺭ ﻊﺑﺎﺗ ﯼﺍﺮﺟﺍ clearTimeout() ﺵﻭﺭ

window.clearTimeout(timeoutVariable)

.ﺖﺷﻮﻧ ﻩﺮﺠﻨﭘ ﺪﻧﻮﺸﯿﭘ ﻥﻭﺪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ window.clearTimeout()

ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺮﯿﻐﺘﻣ ﺯﺍ clearTimeout() ﺵﻭﺭ

myVar = setTimeout(function, milliseconds);
clearTimeout(myVar);

.ﺪﯿﻨﮐ ﻒﻗﻮﺘﻣ ﺍﺭ ﺍﺮﺟﺍ clearTimeout() ﯽﻧﺍﻮﺧﺍﺮﻓ ﺎﺑ ﺪﯿﻧﺍﻮ

ﻝﺎﺜﻣ

:ﻩﺪﺷ ﻪﻓﺎﺿﺍ "ﻒﻗﻮﺗ" ﻪﻤﮐﺩ ﮏﯾ ﺎﺑ ﺎﻣﺍ ،ﻻﺎﺑ ﻝﺎﺜﻣ ﻥﺎﻤﻫ

<button onclick="myVar = setTimeout(myFunction, 3000)">Try it</button>
<button onclick="clearTimeout(myVar)">Stop it</button>

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Timing</h2>

<p>Click "Try it". Wait 3 seconds. The page will alert "Hello".</p>
<p>Click "Stop" to prevent the first function to execute.</p>
<p>(You must click "Stop" before the 3 seconds are up.)</p>

<button onclick="myVar = setTimeout(myFunction, 3000)">Try it</button>

<button onclick="clearTimeout(myVar)">Stop it</button>

<script>
function myFunction() {
  alert("Hello");
}
</script>
</body>
</html>

.()setInterval ﺪﺘﻣ

ﺪﻨﮐ ﯽﻣ ﺭﺍﺮﮑﺗ ﻩﺩﺍﺩ ﺮﻫ ﺭﺩ ﺍﺭ ﻦﯿﻌﻣ ﻊﺑﺎﺗ ﮏﯾ setInterval()

window.setInterval(function, milliseconds);

.ﺖﺷﻮﻧ ﻩﺮﺠﻨﭘ ﺪﻧﻮﺸﯿﭘ ﻥﻭﺪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ window.setInterval()

.ﺩﻮﺷ ﺍﺮﺟﺍ ﺪﯾﺎﺑ ﻪﮐ ﺖﺳﺍ ﯽﻌﺑﺎﺗ ﺮﺘﻣﺍﺭﺎﭘ ﻦﯿﻟﻭﺍ

ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﮏﯾ ﺮﻫ ﻦﯿﺑ ﯽﻧﺎﻣﺯ ﻪﻠﺻﺎﻓ ﻝﻮﻃ ﻡﻭﺩ ﺮﺘﻣﺍﺭﺎﭘ

ﻝﺎﺘﯿﺠﯾﺩ ﮏﯾ ﺪﻨﻧﺎﻣ) ﺪﻨﮐ ﯽﻣ ﺍﺮﺟﺍ ﺭﺎﺑ ﮏﯾ ﻪﯿﻧﺎﺛ ﺮﻫ ﺍﺭ myTimer ﻡﺎﻧ ﻪﺑ ﯽﻌﺑﺎﺗ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

:ﯽﻠﻌﻓ ﻥﺎﻣﺯ ﺶﯾﺎﻤﻧ

setInterval(myTimer, 1000);
 
function myTimer() {
  const d = new Date();
  document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Timing</h2>

<p>A script on this page starts this clock:</p>

<p id="demo"></p>

<script>
setInterval(myTimer, 1000);

function myTimer() {
  const d = new Date();
  document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>

</body>
</html>

.ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ 1000 ﻪﯿﻧﺎﺛ ﮏﯾ ﺭﺩ


؟ﻢﯿﻨﮐ ﻒﻗﻮﺘﻣ ﺍﺭ ﻡﺍﺪﻋﺍ ﻪﻧﻮﮕﭼ

.ﺪﻨﮐ ﯽﻣ ﻒﻗﻮﺘﻣ ﺍﺭ ﻊﺑﺎﺗ ﯼﺍﺮﺟﺍ clearInterval() ﺵﻭﺭ

window.clearInterval(timerVariable)

.ﺖﺷﻮﻧ ﻩﺮﺠﻨﭘ ﺪﻧﻮﺸﯿﭘ ﻥﻭﺪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ window.clearInterval()

:ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ setInterval() ﺯﺍ ﻩﺪﺷ ﻩﺪﻧﺍﺩﺮﮔﺮﺑ ﺮﯿﻐﺘﻣ

let myVar = setInterval(function, milliseconds);
clearInterval(myVar);

ﻝﺎﺜﻣ

:ﻢﯾﺍ ﻩﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺍﺭ "Stop time" ﻪﻤﮐﺩ ﺎﻣ ﺎﻣﺍ ،ﻻﺎﺑ ﻝﺎﺜﻣ ﺪﻨﻧﺎﻣ

<p id="demo"></p>
<button onclick="clearInterval(myVar)">Stop time</button>
 
<script>
let myVar = setInterval(myTimer, 1000);
 function myTimer() {
  const d = new Date();
  document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Timing</h2>

<p>A script on this page starts this clock:</p>

<p id="demo"></p>

<button onclick="clearInterval(myVar)">Stop time</button>

<script>
let myVar = setInterval(myTimer ,1000);
function myTimer() {
  const d = new Date();
  document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>

</body>
</html>

ﺮﺘﺸﯿﺑ ﯼﺎﻫ ﻪﻧﻮﻤﻧ

ﺮﮕﯾﺩ ﻩﺩﺎﺳ ﯼﺪﻨﺑ ﻥﺎﻣﺯ ﮏﯾ

<!DOCTYPE html>
<html>
<body>

<h2>JavaSript setTimeout()</h2>

<p id="demo">I will display when two, four, and six seconds have passed.</p>

<script>
setTimeout(myTimeout1, 2000) 
setTimeout(myTimeout2, 4000) 
setTimeout(myTimeout3, 6000) 

function myTimeout1() {
  document.getElementById("demo").innerHTML = "2 seconds";
}
function myTimeout2() {
  document.getElementById("demo").innerHTML = "4 seconds";
}
function myTimeout3() {
  document.getElementById("demo").innerHTML = "6 seconds";
}
</script>

</body>
</html>

ﺖﺳﺍ ﻩﺪﺷ ﺩﺎﺠﯾﺍ ﯼﺪﻨﺑﻥﺎﻣﺯ ﺩﺍﺪﯾﻭﺭ ﮏﯾ ﺎﺑ ﻪﮐ ﯽﺘﻋﺎﺳ

<!DOCTYPE html>
<html>

<body onload="startTime()">

<h2>JavaScript Clock</h2>

<div id="txt"></div>

<script>
function startTime() {
  const today = new Date();
  let h = today.getHours();
  let m = today.getMinutes();
  let s = today.getSeconds();
  m = checkTime(m);
  s = checkTime(s);
  document.getElementById('txt').innerHTML =  h + ":" + m + ":" + s;
  setTimeout(startTime, 1000);
}

function checkTime(i) {
  if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
  return i;
}
</script>

</body>
</html>

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024