简体   繁体   English

提交表格外的按钮

[英]Submit Button Outside Form

I have a checkout page that is designed like this: 我有一个设计如下的结帐页面:

<!-- Checkout Info Section >
    <form>
        <!-- Address Info >
        <!-- Shipping Option >
        <!-- Payment Info >
        <!-- Totals >
        <!-- Place Order Button >
    </form>


<!-- Order Summary Section >
    <!-- Cart Item>
        <form>
            <!-- Id >
            <!-- Quantity >
        </form>

    <!-- Cart Item>
        <form>
            <!-- Id >
            <!-- Quantity >
        </form>

    etc.

If the quantity of a cart item is changed, the quantity of the cart item is updated via AJAX. 如果更改了购物车项目的数量,则通过AJAX更新购物车项目的数量。

My problem is that I would like to have the Place Order button at the bottom of the page below the Order Summary section. 我的问题是我想在订单摘要部分下面的页面底部放置下订单按钮。 However, the Place Order button must be inside the checkout info form to act as a submit button. 但是,“下订单”按钮必须位于结帐信息表单内,以充当提交按钮。

I have a few options: 我有几个选择:

  1. I can change the order of the page so that the Order Summary section is on top and the Checkout Info section is at the bottom. 我可以更改页面的顺序,以便“订单摘要”部分位于顶部,“结帐信息”部分位于底部。 This is the simplest way to get the Place Order button at the bottom, but I don't like the way it looks. 这是将Place Order按钮放在底部的最简单方法,但我不喜欢它的外观。

  2. I can make the Place Order button position: fixed so that it sticks to the bottom of the page at all times. 我可以将下订单按钮position: fixed以便它始终粘在页面底部。 However, this crowds the screen on mobile phones and is a bit confusing because it will show at all times, even before the customer has filled out the necessary information for ordering. 然而,这会挤在手机屏幕上并且有点混乱,因为它会在任何时候显示,甚至在客户填写订购所需的信息之前。

  3. I can create a dummy button at the bottom of the page that is not contained inside any form. 我可以在页面底部创建一个虚拟按钮,该按钮不包含在任何表单中。 I can then use Javascript to listen for clicks on this button. 然后我可以使用Javascript来听取此按钮的点击次数。 Whenever it is clicked, it can click the Place Order button that still resides inside the form. 无论何时单击它,它都可以单击仍位于表单内的“下订单”按钮。 This button that still sits inside the form can be hidden so that only one Place Order button is present on the page at one time. 仍然位于表单内的此按钮可以隐藏,以便一次只有一个“下订单”按钮出现在页面上。

Option 3 looks the best to me visually. 选项3在视觉上对我来说是最好的。 However, I am concerned about the reliability of this solution. 但是,我担心这个解决方案的可靠性。 If Javascript is not enabled or something prevents the click event from triggering, the customer may be unable to place her order. 如果未启用Javascript或某些内容阻止触发点击事件,则客户可能无法下订单。 Is this a valid concern? 这是一个有效的问题吗?

Does anyone have any other suggestions for achieving this setup with the Place Order button at the bottom of the page? 有没有人对页面底部的下订单按钮实现此设置有任何其他建议?

You can just get any button to submit any form you'd like. 你可以得到任何按钮来提交你想要的任何表格。

<button onclick="document.myFormName.submit()">Checkout</button>

Or in jQuery... 或者在jQuery中......

$('button#my-button').on('click', function() {
    $('form#checkout').trigger('submit');
});

How much content is actually below the form? 表格下面有多少内容? Is there any way you could just have one big form tag that encapsulates the different order sections, as well as the Checkout button? 有没有什么方法可以只有一个大的表单标签封装不同的订单部分,以及Checkout按钮?

Otherwise, could you try position:absolute to position the button below the fold at the bottom of the page, as opposed to position: fixed. 否则,您可以尝试使用position:absolute将按钮定位在页面底部的折叠下方,而不是位置:fixed。 That way it would always sit at the bottom and not scroll with the page. 这样它总是位于底部而不是滚动页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM