简体   繁体   中英

Javascript Pop-up alert - Days countdown Inside alert (7 - 0 days)

I have a pop-up alert in JS and HTML that has to popup if a ticket is older than 7 days. When the ticket does pop up, a user has another 7 days to respond to the ticket, so it accumulates to a total of 14 days.

My issue is as follows: If the pop-up appears, it must show in the alert that a person has 7 days to respond to the ticket, but within the alert the 7 days must drop a day in the alert every 24 hours, but I seem to be struggeling with that, I have some screenshots and code, perhaps I am missing something or show me what I can add or do.

HTML/JS Alert POPUP

Thanks in advance.

Just to be clear if I got you right, these should be the shown remaining times:

 7 days old --> showing 7 days left
10 days old --> showing 4 days left
13 days old --> showing 1 day left
14 days old --> showing 0 days left

In code this should read:

let eventDate= moment(lastEvent.event_date_time);
let dayDifference = moment().diff(eventDate, 'days');

// Even if the popup appears after 7 days, we can still use the total time 
// of 14 days for calculation of the remaining time to be shown.
$scope.tempData.autoClosedDaysLeft = (14 - dayDifference < 0) ? 0 : (14 - dayDifference);

// if the remaining time equals 0, "showAutoCloseAlert" should be set to true.
$scope.tempData.showAutoCloseAlert = ($scope.tempData.autoClosedDaysLeft === 0);

By the way, it should read " previousEvent " rather than " prevoisEvent " :-)

Here's a Fiddle that should give you an idea if that is what you are looking for.

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