我需要在一天内的上午11:30和晚上8:30自动提交表格。
这是提交按钮:
<input type="submit" id="submit" name="submit" />
我需要通过jquery
解决方案。
答案 0 :(得分:2)
试试这个:
<script>
window.addEventListener("load", function() {
// Check time and update the button's state every second.
setInterval(updateSubmitButton, 1000);
}, false);
function updateSubmitButton() {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
// at 11.30 am and at 8.30 pm
if ((hours === 11 && minutes === 30)
|| (hours === 20 && minutes === 30)) {
document.getElementById('submit').click();
} else {
console.log( "Wait for specified time" );
}
}
</script>
答案 1 :(得分:0)
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
if( hours === 20 && minutes === 30 || hours === 23 && minutes === 30 ) {
document.getElementById("myForm").submit();
}
else {
console.log( "Not yet time" );
}
答案 2 :(得分:0)
同样如下:
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var count_minutes = hours*60 + minutes;
var time_out = 0;
var time_interval = 0;
// 690 = 11h 30 am
// 1230 = 8h 30 pm
if (count_minutes <= 690) {
time_out = 690 - count_minutes;
// 540 = 9h from 11h 30 am to 8h 30 pm
time_interval = 540;
}
else if (690 < count_minutes <= 1230) {
time_out = 1230 - count_minutes;
// 900 = 15h from 8h 30 pm to 11h 30 am
time_interval = 900;
}
else {
time_out = (24*60 - count_minutes) + 510;
time_interval = 540;
}
setTimeOut(function(){
submitForm();
setInterval(function(){
submitForm();
}, 24*60*60*1000);
setInterval(function(){
submitForm();
}, time_interval*60*1000);
},time_out*60*1000);
function submitForm () {
// code submit
// $('#submit').trigger('click');
}
&#13;