Программирование на jquery
Anonymous
Маскировка Аадхаара
Сообщение
Anonymous » 28 июн 2024, 11:32
Я пытаюсь обнаружить нажатие кнопки «Назад» в поле ввода. Я пробовал e.key и e.what, который не определен в мобильном Chrome. Как я могу заставить это работать? На рабочем столе все работает нормально.
Код: Выделить всё
jQuery(function($) { // DOM ready and $ alias secured
let aadhaar = "";
let aadhaarStack = [];
let maskStack = [];
let flag = 0;
$('#aadhaar').on('input', function(e) {
let key = e.which || this.value.substr(-1).charCodeAt(0);
console.log("here also")
if (flag === 1) {
console.log("here")
aadhaarStack.pop();
maskStack.pop();
} else {
key = String.fromCharCode(key);
if (aadhaarStack.filter(i => i !== " ").length 1 && (aadhaarStack.filter(i => i !== " ").length) % 4 === 0) {
aadhaarStack.push(" ");
aadhaarStack.push(key);
maskStack.push(" ");
if (aadhaarStack.filter(i => i !== " ").length > 8) {
maskStack.push(key);
} else {
maskStack.push("X");
}
} else {
aadhaarStack.push(key);
if (aadhaarStack.filter(i => i !== " ").length > 8) {
maskStack.push(key);
} else {
maskStack.push("X");
}
}
}
}
updateUi();
});
function updateUi() {
setTimeout(function() {
aadhaar = maskStack.join("");
$('#aadhaar').val(aadhaar);
}, 100);
}
$('#aadhaar').on('keydown', function(e) {
alert(e.key);
let key = e.which || this.value.substr(-1).charCodeAt(0);
if (key === 8 || key === 46 || e.key === 'Backspace') {
flag = 1;
} else {
flag = 0;
}
console.log("first here")
})
});
Вот ссылка на JSBin
https://jsbin . com/rogepevutu/1/edit?html,js,console,output
Подробнее здесь:
https://stackoverflow.com/questions/597 ... ar-masking
1719563526
Anonymous
Я пытаюсь обнаружить нажатие кнопки «Назад» в поле ввода. Я пробовал e.key и e.what, который не определен в мобильном Chrome. Как я могу заставить это работать? На рабочем столе все работает нормально. [code]jQuery(function($) { // DOM ready and $ alias secured let aadhaar = ""; let aadhaarStack = []; let maskStack = []; let flag = 0; $('#aadhaar').on('input', function(e) { let key = e.which || this.value.substr(-1).charCodeAt(0); console.log("here also") if (flag === 1) { console.log("here") aadhaarStack.pop(); maskStack.pop(); } else { key = String.fromCharCode(key); if (aadhaarStack.filter(i => i !== " ").length 1 && (aadhaarStack.filter(i => i !== " ").length) % 4 === 0) { aadhaarStack.push(" "); aadhaarStack.push(key); maskStack.push(" "); if (aadhaarStack.filter(i => i !== " ").length > 8) { maskStack.push(key); } else { maskStack.push("X"); } } else { aadhaarStack.push(key); if (aadhaarStack.filter(i => i !== " ").length > 8) { maskStack.push(key); } else { maskStack.push("X"); } } } } updateUi(); }); function updateUi() { setTimeout(function() { aadhaar = maskStack.join(""); $('#aadhaar').val(aadhaar); }, 100); } $('#aadhaar').on('keydown', function(e) { alert(e.key); let key = e.which || this.value.substr(-1).charCodeAt(0); if (key === 8 || key === 46 || e.key === 'Backspace') { flag = 1; } else { flag = 0; } console.log("first here") }) });[/code] [code] [/code] Вот ссылка на JSBin https://jsbin. com/rogepevutu/1/edit?html,js,console,output Подробнее здесь: [url]https://stackoverflow.com/questions/59737177/aadhaar-masking[/url]