[使用保存的卡片或元素时,我需要在点击提交时验证一个或另一个。
我可以轻松看到自己保存的插卡收音机,但Stripe元素位于iframe中。
填写卡后是否会触发事件?或以某种方式检查是否可以提交。我确定我缺少明显的东西。
类似这种情况
form.addEventListener('submit', function(event) {
event.preventDefault();
$('button.buy').prop('disabled', true);
if ($('.saved_cards input[type="radio"]:checked')) {
self.save_card = false;
self.payment_method = $('.saved_cards input[type="radio"]:checked').val();
self.make_payment().then(self.handleMakePaymentResponse);
} else {
// There should be a way to validate card is filled out
// Stripe validates as you type but no way to know it is simply done.
// we need to know this is filled out.
stripe.createPaymentMethod({
.........
您将在Element上侦听change
事件,然后在事件处理程序对象上检查complete
字段:https://stripe.com/docs/js/element/events/on_change?type=cardElement