我想顯示每小時的彈出模式,就像從 10 到 6 開始一樣,以撰寫登錄用戶報告。它應該像 10 點鐘彈出視窗一樣,用戶撰寫他們的報告并關閉它。1 小時后,即 11 點鐘再次彈出視窗將顯示。
我正在使用 laravel 7、javascript 和 jquery。這些語言中的任何一種對我來說都很方便。請幫我。
這是我到目前為止使用的代碼
** 用于彈出模態的 javascript 代碼 **
setInterval(function () {
get_task_data();
}, 3600000);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
function get_task_data() {
$.ajax({
url: '{{ route('project.employee.task') }}',
type:'GET',
data: { }
}).done(function(data){
$('#myModal .modal-body').append(data);
$('#myModal').modal('show');
});
}
但我想彈出模態正好 10 0'clock ,11 o'clock 等等直到 6 0'clock。
已編輯
我想每小時發送“桌面通知”“請發送您的報告”這樣的東西。我該怎么做?
uj5u.com熱心網友回復:
如果沒問題,您可以使用 Window setInterval() 方法
如何使用 ?
setInterval(function(){
// Call your modal popup init function here__
}, 3600000);
3600000 = 3600 秒 = 60 分鐘 = 1 小時
了解有關設定間隔的更多資訊單擊此處
以下示例,代碼將用于顯示每隔一小時的警報彈出視窗
setInterval(function(){
alert("Hello");
}, 3600000);
更新的代碼片段
此代碼將用于在 10 0 點鐘、11 點鐘等精確到 6 點鐘顯示彈出模式。
var currentDate = new Date(); // get your current date and time__
var curentHour = currentDate.getHours(); // get Hours of your current time__
var curentMinutes = currentDate.getMinutes(); // get minutes of your current time__
var intervalId = null;
var varCounter = 0; // count the display times, and set initial value
var displayTimes = 9; // between 10'O clock to 6'O clock modal has to display 9 times
// stop function arround 6'O clock
var varModal = function(){
if(varCounter < 10) {
varCounter ; // you can remove this code
alert(varCounter 'time'); // you can remove this code
/* your code goes here */
} else {
// stop modal duisplay after 9 times, it's mea after on 6'O clock
clearInterval(intervalId);
alert('Stop will start on next day'); // you can remove this code
}
};
/*
* display modal arround 10'O clock,
* This function will trigger after each one hour,
* So you have to set value 9, then only it'trigger arround 10'O clock
* -------
* If you want to trigger this modal arround 9'O clock, you have to check with value 8
*/
if(curentHour >= 9 && curentMinutes > 0){
intervalId = setInterval(varModal, 3600000);
}
uj5u.com熱心網友回復:
使用類似 100/200 毫秒延遲的間隔,然后檢查當前分鐘是否為 0。為了避免多次呼叫,請檢查當前 Hm 是否與上次呼叫不同。
let last = null;
setInterval(function() {
const d = new Date();
const curr_hm = `${d.getHours()}-${d.getMinutes()}`;
if (d.getMinutes() == 0 && curr_hm != last) {
console.log('Do task here!');
last = curr_hm;
}
}, 200);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/348600.html
標籤:javascript php 查询 拉拉维尔 laravel-7
