我想显示一个仅在特定日期显示的警报框。
<script>
alert('Registration Time is Over !!!');
</script>
我该怎么做?
答案 0 :(得分:0)
<script>
var alertdate = "12/18/2018";
var alerttext = "Registration time is over!";
var d = new Date();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
today = mm + '/' + dd + '/' + yyyy;
if(today == alertdate){
alert(alerttext)
}
</script>
将警报日期更改为以下格式的日期: 月日年 将Alerttext更改为所需的文本。
答案 1 :(得分:-1)
使用超时。
var currentDateMillis = new Date().getTime(); // Get time on millis
var alarmDateMillis = new Date(year, month, day, hours, minutes, seconds, milliseconds).getTime();
if (alarmDateMillis > currentDateMillis)
setTimeout (alarm, alarmDateMillis - currentDate);
else // This is in case you want it to be shown even after the date
alarm();
function alarm () {
alert('Registration Time is Over !!!');
}