我对JavaScript真的很陌生,我想向您提出一个问题:
form.addEventListener('submit', (e) => {
const choice = document.querySelector('input[name=os]:checked').value;
const data = {os:choice}
fetch('localhost:3000/poll', {
method: 'post',
body: JSON.stringify(data),
headers: new Headers({
'Content-Type': 'application/json'
})
})
.then(res => res.json())
.then(data => console.log(data))
// alert("Danke für die Abstimmung")
.catch(err => console.log(err));
e.preventDefault();
});
这是我的代码。我正在调用“提交”按钮,并为每次点击添加选中的值。我想添加一个倒计时并说:每60秒仅计算一次用户点击。其他显示警报。
我该怎么办?
您可以使用flag检查时差。用户单击提交按钮后,您可以在变量中存储时间。如果用户再次单击提交按钮,请检查当前时间与上次提交时间之间的差异(将其存储在变量中)。如果时间差小于60秒,请显示警报消息,否则请执行发布请求。
希望,有帮助。