简体   繁体   English

代码可以在 jsfiddle 上运行,但不能在我的网站上运行吗?

[英]code work on jsfiddle but not on my website?

Hey so recently i found some code online while looking for a method that can recognize the type of credit card as the numbers are being typed, i tried out the code on jsfiddle.net and it seemed to work fine, untill i decided to copy and paste the code into a blank .php file, the code will apear, i get no errors but it just wont do what its supposed to do.嘿,最近我在网上找到了一些代码,同时寻找一种可以在输入数字时识别信用卡类型的方法,我在 jsfiddle.net 上尝试了代码,它似乎工作正常,直到我决定复制和将代码粘贴到一个空白的 .php 文件中,代码将出现,我没有收到任何错误,但它只是不会做它应该做的事情。 am i typing the code in the wrong places or something?我是在错误的地方输入代码还是什么?

here is a link to original JSfiddle: http://jsfiddle.net/ipsjolly/9whmL9u0/这是原始 JSfiddle 的链接: http : //jsfiddle.net/ipsjolly/9whmL9u0/

and here is my .php file:这是我的 .php 文件:

 function detectCardType(number) { var re = { electron: /^(4026|417500|4405|4508|4844|4913|4917)\\d+$/, maestro: /^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|0604|6390)\\d+$/, dankort: /^(5019)\\d+$/, interpayment: /^(636)\\d+$/, unionpay: /^(62|88)\\d+$/, visa: /^4[0-9]{12}(?:[0-9]{3})?$/, mastercard: /^5[1-5][0-9]{14}$/, amex: /^3[47][0-9]{13}$/, diners: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/, discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/, jcb: /^(?:2131|1800|35\\d{3})\\d{11}$/ }; if (re.electron.test(number)) { return 'ELECTRON'; } else if (re.maestro.test(number)) { return 'MAESTRO'; } else if (re.dankort.test(number)) { return 'DANKORT'; } else if (re.interpayment.test(number)) { return 'INTERPAYMENT'; } else if (re.unionpay.test(number)) { return 'UNIONPAY'; } else if (re.visa.test(number)) { return 'VISA'; } else if (re.mastercard.test(number)) { return 'MASTERCARD'; } else if (re.amex.test(number)) { return 'AMEX'; } else if (re.diners.test(number)) { return 'DINERS'; } else if (re.discover.test(number)) { return 'DISCOVER'; } else if (re.jcb.test(number)) { return 'JCB'; } else { return undefined; } } $(function(){ $(".ckthis").keyup(function(){ var thisNum = $(this).val(); console.log(thisNum); $(".showThis").html(detectCardType(thisNum)); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script> <input type="text" class="ckthis"> <div class="showThis"></div> <br><br> SAMPLE TEST NUMBERS <br><br> VISA:4539435089757850<br><br>

I can't see you've included your JQuery library.我看不到你已经包含了你的 JQuery 库。

Put this somewhere in your code (eg at the bottom, above your <script> tags)把它放在你的代码中的某个地方(例如在底部,在你的<script>标签上方)

<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

Or you can download the whole library locally to your computer and refer to it that way instead.或者,您可以将整个库本地下载到您的计算机上,然后以这种方式进行引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM