简体   繁体   中英

javascript trouble alert specific time

I get the clock working fine, counting current time, but i want an alert box to pop up when it is a specific time... Any help here?

window.onload = oppstart;


function oppstart() {

    var tid = new Date();

    var timer = tid.getHours();

    var minutter = tid.getMinutes();

    var sekunder = tid.getSeconds();

    document.getElementById("tiden").innerHTML = tid.getHours() + ":" + tid.getMinutes() + ":" +  tid.getSeconds();

    setTimeout(oppstart,1000);

    if(tid == 13.28){
        alert("Nå er klokka 13.28!!")
    }
} 

tid is an object of class Date . It is not something you should compare with a number expecting it to be hour.minutes .

Change:

if(tid == 13.28){

to:

if (timer == 13 && minutter == 28) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM