Я нашел отзыв о подсказке полезным, чтобы устранить эту проблему в Tomcat -
, обязательно загрузите драйвер, сначала выполнив Class.forName («org.postgresql.Driver»); в вашем коде.
Это из сообщения - https://www.postgresql.org/message-id/e13c14ec050510103846db6b0e@mail.gmail.com
Код jdbc работал нормально как автономная программа, но в TOMCAT он дал ошибку «Не найден подходящий драйвер»
Я не уверен, что это сработает, я также изучаю javascript. Предположим, есть функция нажатия кнопки под названием click1()
, а есть функция loadclick1()
, так что вкратце это будет выглядеть как
function loadclick1() {
if (//button-clicked) {
function click1() {
//Animation code here;
setTimeout(loadclick1(), 3000) //This will set a timeout until the function is ready
}
}
}
То, о чем вы думаете, называется «регулирование»
Этот вопрос SO имеет решение для вас: Простой газ в js
Бесстыдная копия пасты выше:
// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time. Normally, the throttled function will run
// as much as it can, without ever going more than once per `wait` duration;
// but if you'd like to disable the execution on the leading edge, pass
// `{leading: false}`. To disable execution on the trailing edge, ditto.
function throttle(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function() {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
};
просто поместите переменную delay
и lastClick в ваш код. Я проверил это, оно работает:
var delay = 800;
var lastClick = 0;
var images = [
"url(https://cdn.discordapp.com/attachments/461567193927385091/534789187560407045/picture1.png)",
"url(https://cdn.discordapp.com/attachments/461567193927385091/534789189162762240/picture2.png)",
"url(https://cdn.discordapp.com/attachments/461567193927385091/534789190500614147/picture3.png)",
"url(https://cdn.discordapp.com/attachments/461567193927385091/534789199837265929/picture4.png)"];
var num = 0;
var interval = setInterval(next, 5000);
function next(){
console.log(lastClick);
if (lastClick >= (Date.now() - delay))
return;
lastClick = Date.now();
var diashow = document.getElementById("diashow");
num++;
if(num >= images.length){num = 0;}diashow.style.backgroundImage = images[num];}
function prev(){
if (lastClick >= (Date.now() - delay))
return;
lastClick = Date.now();
var diashow = document.getElementById("diashow");
num--;
if(num < 0) {num = images.length-1;}diashow.style.backgroundImage = images[num];}
function stop(){clearInterval(interval);}
function set(){interval = setInterval(next, 5000);}
Не стесняйтесь редактировать переменную delay
.
PS: ключевое слово var
устарело, ознакомьтесь с let
и const
.