如何在html输入的四个字符后插入空格?

问题描述:

在用户使用JavaScript输入信用卡号时,我需要在每四个字符后插入一个空格.

I need to insert a space after every four characters while the user is typing a credit card number using JavaScript .

<input type="text" size="19" maxlength="19" data-stripe="number" placeholder="1234 5678 9012 3456">

完成此任务的最佳方法是什么?

What is the best way to accomplish this ?

您可以使用jquery和mask进行检查,请检查它 jquery and mask 对于jQuery,您只需要戴上面具

you can use a jquery and mask for it please check it jquery and mask for jquery you only need put a mask

$("#date").mask("9999 9999 9999 9999");

选中它