I have the following function hooked into my Wordpress plugin.
function before_submit() {
document.getElementById('page-loader').style.display='block';
}
This hook is being called before it submits a form. Now what i would like to do is to get the div id page-loader
for a specific number of seconds, before it actually submits the form. I've read about the settimeout function and tried some stuff, but i cannot get it working. I guess the settimeout function is to run a script after a certain number of seconds instead of running it for a number of seconds correct?
So i'd like the script to have a 'running time' of, for instance, 4 seconds. Now it runs the script and submits the form immidiately
Tried this but it's not working:
function before_submit()
{
function partA() {
document.getElementById('page-loader').style.display='block';
window.setTimeout(partB,1000)
}
function partB() {
//let's go submit the form
}
}
Please help me out. Thank you so much!
This is the format you're looking for:
// Note, in the fiddle, this is run during the window.onload event.
var test = document.getElementById('test');
test.addEventListener('submit', function before_submit(e){
document.getElementById('wait').style.display = 'block';
setTimeout(function wait(){
// After waiting for five seconds, submit the form.
test.submit();
}, 5000);
// Block the form from submitting.
e.preventDefault();
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다