5秒后自动提交表单
我有一个表单,我试图在页面加载后提交,并且 5 秒过去了。我已经尝试过 setTimeout 但它似乎不起作用。任何人都可以建议为什么会出现这种情况,我在上面有 jQuery网站但无法让延迟()工作
<form action="" name="cartCheckout" id="cartCheckout" method="post">
<input type="hidden" name="action" value="checkout" />
<input type="hidden" name="save" value="1" />
<input type="hidden" name="orderID" value="<?php echo $GLOBALS['CHECKOUT_ORDERID']; ?>" />
<div class="itembox" id="step4box">
<div id="progress">
<ul>
<li>Your Cart</li>
<li>Your Details</li>
<li class="current">Payment</li>
<li>Confirmation</li>
</ul>
</div>
<div id="words" class="gothbold">Please wait while we we redirect you to<br />Paypal for a secure payment method.</div>
<a class="redirect" href="javascript:void(0)" title="Proceed to Paypal" onClick="document.cartCheckout.submit();"><span>If you aren't redirected in 5 seconds click here</span></a><br />
<a class="cancel" href="javascript:void(0)" title="Return to details" onClick="jQuery('#step4box').hide();jQuery('#step2box').show();"><span>Cancel</span></a>
</div>
<script type="text/javascript">
window.onload=function(){
window.setTimeout(document.cartCheckout.submit(), 5000);
};
</script>
</form>
任何帮助将不胜感激,提前致谢
编辑:
通过@Alex,@user824294和这个问题的组合更改为此:如何使用 jquery 创建一个以登录弹出窗口结束的 5 秒倒计时器?。现在工作得很好,并且具有强大的倒计时功能。谢谢你们!
window.onload=function(){
var counter = 5;
var interval = setInterval(function() {
counter--;
$("#seconds").text(counter);
if (counter == 0) {
redirect();
clearInterval(interval);
}
}, 1000);
};
function redirect() {
document.checkout_paypal.submit();
}
I have a form that i am trying to submit after the page loads and 5 seconds has gone passed.. i have tried setTimeout but it doesnt appear to be working.. can anyone suggest why this would be the case, i have jQuery on the site but couldnt get delay() working either
<form action="" name="cartCheckout" id="cartCheckout" method="post">
<input type="hidden" name="action" value="checkout" />
<input type="hidden" name="save" value="1" />
<input type="hidden" name="orderID" value="<?php echo $GLOBALS['CHECKOUT_ORDERID']; ?>" />
<div class="itembox" id="step4box">
<div id="progress">
<ul>
<li>Your Cart</li>
<li>Your Details</li>
<li class="current">Payment</li>
<li>Confirmation</li>
</ul>
</div>
<div id="words" class="gothbold">Please wait while we we redirect you to<br />Paypal for a secure payment method.</div>
<a class="redirect" href="javascript:void(0)" title="Proceed to Paypal" onClick="document.cartCheckout.submit();"><span>If you aren't redirected in 5 seconds click here</span></a><br />
<a class="cancel" href="javascript:void(0)" title="Return to details" onClick="jQuery('#step4box').hide();jQuery('#step2box').show();"><span>Cancel</span></a>
</div>
<script type="text/javascript">
window.onload=function(){
window.setTimeout(document.cartCheckout.submit(), 5000);
};
</script>
</form>
any help would be greatly appreciated, thanks in advance
EDIT:
changed to this via a combination of @Alex, @user824294 and this question: How Can I create A 5 second Countdown timer with jquery that ends with a login popup?. Now working great and with great functionality of a countdown. Thanks guys!
window.onload=function(){
var counter = 5;
var interval = setInterval(function() {
counter--;
$("#seconds").text(counter);
if (counter == 0) {
redirect();
clearInterval(interval);
}
}, 1000);
};
function redirect() {
document.checkout_paypal.submit();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
相反,传递对该函数的引用。
...或者...
您当前正在执行该函数,然后将其返回值传递给
setTimeout()
。另外,如果您希望执行更接近 5 秒的时间,则需要使用
setInterval()
或递归setTimeout()
并检查+new Date< /代码>。
Pass a reference to the function instead.
...or...
You are currently executing the function, and then passing its return value to
setTimeout()
.Also, if you wish to execute closer to exactly 5 seconds, you'd need to a
setInterval()
or recursivesetTimeout()
and examine+new Date
.你可以把它变得非常简单,试试这个:
You can have it realy simple, try this guys :
尝试这样做:
Try doing this instead: