No.101, Sec.2, Kuang-Fu Rd., HsinChu City, Taiwan 新竹市光復路二段101號
+886-571-5131#35162
klou@mx.nthu.edu.tw

setTimeout

Lab of AR/VR/XR & Machine Learning

setTimeout

<!DOCTYPE html>
<html>
<body>

<h1>離畢業日期還有幾天</h1>

年<input type=input id="p1"><br>
月<input type=input id="p2"><br>
日<input type=input id="p3">
<input type=button onclick="setTimeout('myFunction()',1000)" value="算算看">
<p id="demo"></p>
<script>
function myFunction() {
    var p1= document.getElementById("p1").value;
    var p2= document.getElementById("p2").value;
    var p3= document.getElementById("p3").value;
    var today =new Date();
    var graduate = new Date();
    graduate.setFullYear(p1,p2-1,p3);
    graduate.setHours(12);
    graduate.setMinutes(0);
    graduate.setSeconds(0);
    document.getElementById("demo").innerHTML = 
    (graduate-today)/1000;
    setTimeout('myFunction()',1000);
}
    
function yourFunction() {
    var p1= document.getElementById("p1").value;
    document.getElementById("demo").innerHTML = (p1-32)*5/9;
}

</script>

</body>
</html>