条纹的输入卡元素的jQuery选择器未得到任何结果

时间:2018-07-08 01:27:58

标签: javascript jquery stripe-payments

我正在尝试向Card()元素生成的条纹形式添加小卡片显示插件。但是我无法获取jquery选择器来获取输入。我怀疑在输入console.log()

时,尚未将输入添加到DOM中。

这是我的代码:

   var card = elements.create('card', { style: style } );

    // Add an instance of the card Element into the `card-element` <div>
    card.mount('#card-element');

    card.addEventListener('change', function(event) {
      var displayError = document.getElementById('card-errors');
      if (event.error) {
        displayError.textContent = event.error.message;
      } else {
        displayError.textContent = '';
      }
    });

    card.on('ready', function(){
        console.log('The input', $('input[name="cardnumber"'));
        $('form').card({
            // a selector or DOM element for the container
            // where you want the card to appear
            container: '.card-wrapper', // *required*
            formSelectors: {
                numberInput: 'input[name="cardnumber"]', // optional — default input[name="number"]
                // expiryInput: 'input[name="expdate"]', // optional — default input[name="expiry"]
                // cvcInput: 'input[name="cvc"]', // optional — default input[name="cvc"]
                // nameInput: 'input[name="name"]' // optional - defaults input[name="name"]
            },
            placeholders: {
                name: 'Cliente Chopinmol',
                expiry: 'expdate',
                cvc: 'cvc'
            }
            // all of the other options from above
        });
    })

执行console.log('The input', $('input[name="cardnumber"'));行时,即使我可以在浏览器的HTML上看到它,选择器上也没有输入元素。

任何人都可以告诉我,为了确保在我调用jQuery时该元素位于DOM上,我必须使用什么事件/回调?

谢谢

0 个答案:

没有答案