我有一个简单的注册表单和提交按钮:
<input type="submit" value="" class="loginInput" id="submitReg" />
和javascript函数以确保页面加载和表单提交之间的毫秒时间:
(function () {
var element = document.getElementById('submitReg'),
start, end;
window.onload = function (event) {
start = +event.timeStamp;
};
element.onclick = function (event) {
end = +event.timeStamp;
var diff = end - start; // time difference in milliseconds
//alert(diff);
};
})();
如何执行此操作,仅在diff>3000
时才允许表单提交?我想我应该添加return true
/ return false
之类的东西,但我不知道如何。谢谢你的回答!
答案 0 :(得分:1)
在您的情况下,要在条件下提交表单 - 调整您的element.onclick
事件,如下所示:
...
element.onclick = function (event) {
end = +event.timeStamp;
var diff = end - start; // time difference in milliseconds
return (diff > 3000)? true : false;
};
...
答案 1 :(得分:0)