我使用 Stripe 作为我的支付处理器,并实现了一个自定义按钮。但是,我意识到在我允许他们付款之前我还需要检查用户是否输入了运输信息(我意识到我可以将它放在单独的页面上,但我更喜欢他们不必跳转到新页面)。
但是,当我尝试将 IF 添加到 Stripe 表单时,我遇到了问题。这是 JSFiddle:http: //jsfiddle.net/K843E/1/
<form method="post" action="stripeprocess.php" id="cartform2">
<button id="customButton2" type="button">With Check</button>
<script>
var check = false;
if(check) {
$('#customButton2').click(
function() {
var token = function(res) {
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
$('#cartform2').append($input).submit();
};
StripeCheckout.open({
address: true,
amount: 1000,
currency: 'usd',
name: 'Test',
description: 'Item Description',
panelLabel: 'Checkout',
token: token
}
}
);
return false;
});
顶部按钮显示如果 IF 语句返回 true,它应该如何工作,底部按钮是我对 IF 的尝试。