Fire event at a certain time of the day

前端 未结 4 1424
一整个雨季
一整个雨季 2020-12-31 08:08

Is it possible with javascript (jQuery solutions are fine too) to fire an event/call a function at certain times of the day e.g.

call myFunctionA at 10:00

ca

4条回答
  •  臣服心动
    2020-12-31 08:50

    4html:

    current date: 
    time to Alarm:
    alarm Triggered: false

    javascript:

    var setAlarm1 = "14"; //14:00, 2:00 PM
    var int1 = setInterval(function(){
        var currentHour = new Date().getHours();
        var currentMin = new Date().getMinutes();
        $('#cd').html(currentHour + ":" + currentMin );
        $('#al1').html(setAlarm1 - currentHour + " hours");
            if(currentHour >= setAlarm1){
                $('#al1stat').html(" true");
                clearInterval(int1);
                //call to function to trigger : triggerFunction();
            }
        },1000) //check time on 1s
    

    Sample at: http://jsfiddle.net/yhDVx/4/

提交回复
热议问题