我在这里看到了一些其他帖子,但其中没有任何内容对我有帮助(或者他们的解决方案是我已经完成的)。
我的卡确实显示了,但在控制台中出现以下错误:
Card can't find a numberInput in your form.
Card can't find a expiryInput in your form.
Card can't find a cvcInput in your form.
Card can't find a nameInput in your form.
我目前正在使用 jquery.card.js,这是我从此处下载的最新版本 ( https://github.com/jessepollak/card ) 并从“dist”文件夹中提取。
这是我的表格中与该卡专门相关的部分:
<div class="box-body" style="">
<div class='card-wrapper'></div>
<!-- CSS is included via this JavaScript file -->
<input type="text" name="number" class="form-control" id="number">
<input type="text" name="expiry" class="form-control"/>
<input type="text" name="cvc" class="form-control"/>
<input type="text" name="name" class="form-control"/>
</div>
这是我对该卡的设置:
<script>
$('form').card({
// a selector or DOM element for the container
// where you want the card to appear
container: '.card-wrapper', // *required*
// all of the other options from above
formatting: true, // optional - default true
// Strings for translation - optional
messages: {
validDate: 'valid\ndate', // optional - default 'valid\nthru'
monthYear: 'mm/yyyy', // optional - default 'month/year'
},
// Default placeholders for rendered fields - optional
placeholders: {
number: '•••• •••• •••• ••••',
name: 'Full Name',
expiry: '••/••',
cvc: '•••'
},
formSelectors: {
numberInput: 'input[name="number"]', // optional — default input[name="number"]
expiryInput: 'input[name="expiry"]', // optional — default input[name="expiry"]
cvcInput: 'input[name="cvc"]', // optional — default input[name="cvc"]
nameInput: 'input[name="name"]' // optional - defaults input[name="name"]
},
// if true, will log helpful messages for setting up Card
debug: true // optional - default false
});
</script>
正如我之前所说,卡片的图像确实出现了,所以我知道该脚本的部分内容实际上正在工作。
最佳答案
事实证明,我需要将行: $('form').card({
更改为表单的特定 ID。它现在可以工作了。
关于javascript - Card.js - 在表单中找不到数字输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48546805/