5秒后自动提交表单

发布于 2024-12-27 11:44:02 字数 2094 浏览 2 评论 0原文

我有一个表单,我试图在页面加载后提交,并且 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

再浓的妆也掩不了殇 2025-01-03 11:44:02

相反,传递对该函数的引用。

window.onload=function(){ 
    window.setTimeout(document.cartCheckout.submit.bind(document.cartCheckout), 5000);
};

...或者...

window.onload=function(){ 
    window.setTimeout(function() { document.cartCheckout.submit(); }, 5000);
};

您当前正在执行该函数,然后将其返回值传递给 setTimeout()

另外,如果您希望执行更接近 5 秒的时间,则需要使用 setInterval() 或递归 setTimeout() 并检查 +new Date< /代码>。

Pass a reference to the function instead.

window.onload=function(){ 
    window.setTimeout(document.cartCheckout.submit.bind(document.cartCheckout), 5000);
};

...or...

window.onload=function(){ 
    window.setTimeout(function() { document.cartCheckout.submit(); }, 5000);
};

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 recursive setTimeout() and examine +new Date.

陌生 2025-01-03 11:44:02

你可以把它变得非常简单,试试这个:

<form name="xyz"...>
...
<script type="text/javascript">
<!--
   var wait=setTimeout("document.xyz.submit();",5000);
//-->
</script>
</form>

You can have it realy simple, try this guys :

<form name="xyz"...>
...
<script type="text/javascript">
<!--
   var wait=setTimeout("document.xyz.submit();",5000);
//-->
</script>
</form>
攒眉千度 2025-01-03 11:44:02

尝试这样做:

window.onload=function(){ 
    window.setTimeout("redirect()", 5000);
    // OR
    window.setTimeout(function() { redirect(); }, 5000);
};

function redirect() {
    document.cartCheckout.submit();
}

Try doing this instead:

window.onload=function(){ 
    window.setTimeout("redirect()", 5000);
    // OR
    window.setTimeout(function() { redirect(); }, 5000);
};

function redirect() {
    document.cartCheckout.submit();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文