所以我想實現的是每隔四分之後用空格替換。 就像我開始寫在按鍵上輸入1234123412341234, 我想實現1234 1234 1234 1234,當用戶鍵入時。用空格jquery替換每個第四個輸入值之後?
<input type="text" id="number" maxlength=19 />
這裏是JS
$('#number').on('keypress', function() {
if (this.value.length >= 4) {
this.value = this.value.slice(0, 4) + ' '+this.value.slice(5, 9);
}
所以這個代碼僅創建第四後一個空間,1234 123412341234. 但如何對輸入值的其餘部分嗎?提前致謝。
jQuery是不是該解決方案在這裏,你可以用標準的JS做到這一點 - http://stackoverflow.com/questions/32030727/replace-every-nth-character-from- a-string – G0dsquad