gpt4 book ai didi

javascript - Opcheckout 未检测到复选框

转载 作者:行者123 更新时间:2023-11-29 23:46:33 25 4
gpt4 key购买 nike

我正在构建一个电子商务软件并​​卡在付款结帐页面上。我决定使用 OP Checkout,称为 Magento Checkout,并包含所有必需的 JS 文件。问题是当我单击“继续”按钮时,它没有检测到勾选了哪个复选框。当我调试到警报消息时,我发现这行代码需要捕获用户交互。

if ($('login:guest') && $('login:guest').checked) {

HTML 代码:

<div class="col-md-6">
<h3>Checkout as a Guest or Register</h3>
<div class="space10"></div>
<p>Register with us for future convenience:</p>
<div class="cbox">
<input name="checkout_method" id="login:guest" value="guest" class="radio" type="radio"><span for="login:guest">Checkout as Guest</span><br>
<div class="space10"></div>
<input name="checkout_method" id="login:register" value="register" class="radio" type="radio"><span for="login:register">Register</span>
</div>
<div class="space20"></div>
<h4>Register and save time!</h4>
<div class="space10"></div>
<p>Register with us for future convenience:</p>
<ul class="ul">
<li><i class="fa fa-check"></i> Fast and easy check out</li>
<li><i class="fa fa-check"></i> Easy access to your order history and status</li>
</ul>
<div class="space10"></div>

<button id="onepage-guest-register-button" type="button" class="button btn-black" onclick="checkout.setMethod();"><span><span>Continue</span></span></button>
</div>

上面的代码没有捕捉到结果。

最佳答案

id 选择器使用 # 并转义 : from id (Read Selector docs) 就像,

if ($('#login\\:guest').is(':checked')) { //escape : by using \\

另一种使用方式是,

$('[id="login:guest"]').is(':checked');

片段,

$(function() {
$('#btnCheck').on('click', function() {
alert($('#login\\:guest').is(':checked') + ',' + $('[id="login:register"]').is(':checked'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cbox">
<input name="checkout_method" id="login:guest" value="guest" class="radio" type="radio"><span for="login:guest">Checkout as Guest</span><br>
<div class="space10"></div>
<input name="checkout_method" id="login:register" value="register" class="radio" type="radio"><span for="login:register">Register</span>
<button id="btnCheck">Check</button>
</div>

关于javascript - Opcheckout 未检测到复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43800953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com