1.获取不同浏览器按下的键码
$(document).ready(function(){
$("#keydown").keydown(function(event){
var keycode = (event.keyCod ? event.keyCode : event.which);
console.log("keycode:" + keycode);
}
})
})
2.输入卡号卡号规则***** **** **** ****** 中间有空格
$('#cardno').on('input', function () {
//去掉所有空格
this.value = this.value.replace(/\s/g, "");
if (/^[0-9]*[1-9][0-9]*$/.test(this.value)) {
var len = this.value.length;
if (len >= 6 && len <=9) {
this.value = this.value.substring(0, 5) + " " + this.value.substring(5)
} else if (len >= 10 && len <=13) {
this.value = this.value.substring(0, 5) + " " + this.value.substring(5, 9) + " " + this.value.substring(9)
} else if (len >= 14 && len <=20) {
this.value = this.value.substring(0, 5) + " " + this.value.substring(5, 9) + " " + this.value.substring(9, 13) + " " + this.value.substring(13)
}
}
})