0
我已经构建了一个存储消息和用户的页面,以便将消息发送到db中。表单有一个限制:从发布消息到数据库之后的30秒内,不能使用同一个用户。从一小时的最后一分钟到下一小时的第一分钟
function undisable (id,time){
setTimeout(function() {
$('#'+id).prop('disabled', false);
}, (30000-time));
}
$('#destinatario option').each(function(){
var ds = $(this).attr('data-ts');
var dateArray = ds.split(" "); // split the date and time
var ds1 = dateArray[0].split("-"); // split each parts in date
var ds2 = dateArray[1].split(":"); // split each parts in time
var newDate = new Date(ds1[0], (+ds1[1] - 1), ds1[2], ds2[0], ds2[1], ds2[2]).getTime(); //parse it
var currentDate = new Date().getTime();
var diff = currentDate - newDate;
if(diff < 30000){
$(this).prop('disabled', true);
var id = $(this).attr('id');
undisable(id,diff);
}
});
现在我想添加一个新的条件:你不能从一个小时的最后一分钟到下一个的第一分钟发布到任何用户。因此,例如,您不能从10:59:00到11:01:00发帖(以此类推每天的一小时)。 什么是最明智的方法来设置if子句来做到这一点? 我想建立是一样的东西:
if(now(minutes) is between 59 and 01){ //this is the point where I get stuck at
$('#sendbutton').prop('disabled', true); //I cannot post
}else{
$('#sendbutton').prop('disabled', false); //I can post
}
感谢您的帮助!
情况是一点点比较法。加载页面后,我应该可以在两个禁用的mnutes后发布消息。就像我为单件物品做了30秒一样。 –
编辑我的答案做你想做的! –
谢谢! :)正在寻找一个提示,但你给了我一个完整的答案! –