Код: Выделить всё
$(".clstxtInputNumber").inputmask({
alias: 'decimal',
groupSeparator: ',',
autoGroup: true,
digits: gDomesticOverseas == "M" ? 0 : 2,
digitsOptional: false,
rightAlign: false
});
вот мой элемент ввода
Код: Выделить всё
Есть ли способ сделать это.
эта функция запускается, когда я комментирую маску ввода, а затем показывает идеальные значения при использовании английской клавиатуры.
Код: Выделить всё
function DoubleToSingleBytesConversion(ele) {
debugger
var currentValue = $(ele).val();
currentValue = currentValue.replaceAll(',', '');
var regex = /^\d+(\.\d*)?$/;
if (currentValue !== "") {
if (currentValue.includes('0')) {
currentValue = currentValue.replaceAll('0', '0');
}
if (currentValue.includes('1')) {
currentValue = currentValue.replaceAll('1', '1');
}
if (currentValue.includes('2')) {
currentValue = currentValue.replaceAll('2', '2');
}
if (currentValue.includes('3')) {
currentValue = currentValue.replaceAll('3', '3');
}
if (currentValue.includes('4')) {
currentValue = currentValue.replaceAll('4', '4');
}
if (currentValue.includes('5')) {
currentValue = currentValue.replaceAll('5', '5');
}
if (currentValue.includes('6')) {
currentValue = currentValue.replaceAll('6', '6');
}
if (currentValue.includes('7')) {
currentValue = currentValue.replaceAll('7', '7');
}
if (currentValue.includes('8')) {
currentValue = currentValue.replaceAll('8', '8');
}
if (currentValue.includes('9')) {
currentValue = currentValue.replaceAll('9', '9');
}
if (currentValue.length > parseInt($(ele).attr('maxlength'))) {
currentValue = currentValue.slice(0, parseInt($(ele).attr('maxlength')))
}
if (regex.test(currentValue)) {
tempVal = currentValue;
tempVal = parseFloat(tempVal).toFixed(2);
tempVal = ConvertToDigitsWithComma(tempVal)
$(ele).val(tempVal);
}
else {
currentValue = currentValue.replace(/[^\d,.]/g, '');
tempVal = currentValue;
tempVal = parseFloat(tempVal).toFixed(2);
tempVal = ConvertToDigitsWithComma(tempVal)
$(ele).val(tempVal);
}
}
else {
// $(ele).val("0.00");
}
}
function ConvertToDigitsWithComma(txt) {
if (txt instanceof Element || txt instanceof HTMLDocument) {
let value = txt.value.replace(/,/g, ''); // Remove existing commas, if any
// Convert the value to a comma-separated format
let formattedValue = value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// Update the input element's value with the formatted value
txt.value = formattedValue;
} else {
let formattedValue = txt.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return formattedValue
}
// Return false to prevent any default behavior or propagation
return false;
}
то, что я печатаю : "100000.00"
что отображается при вводе: "1100010.00"
Будем благодарны за любую помощь.
Заранее спасибо
Подробнее здесь: https://stackoverflow.com/questions/785 ... ask-jquery
Мобильная версия