Dígame, si cambia el valor del campo en el medio, entonces la función onchange no funciona. Si escribe números al final, entonces la función funciona. El problema solo está en el navegador safari. ¿Cual podría ser el problema?
jQuery.fn.extend({ phone: function() { var maskList = [{ "code": "+7 ### ### ## ##", "country": "RU" }, { "code": "+380 ## ### ## ##", "country": "UA" } ]; var change = function(e) { if (e.type == 'paste') $(this).val(''); cursor_start = $(this).prop('selectionStart'); cursor_end = $(this).prop('selectionEnd'); let matrix = '###############'; if ($(this).val()[0] == '+') { matrix = '+##############'; } maskList.forEach(item => { let code = item.code.replace(/[\s#]/g, ''), phone = $(this).val().replace(/[\s#-)(]/g, ''); if (phone.includes(code)) { matrix = item.code; } }); let i = 0, val = $(this).val().replace(/\D/g, ''); value = matrix.replace(/(?!\+)./g, function(a) { return /[#\d]/.test(a) && i < val.length ? val.charAt(i++) : i >= val.length ? '' : a; }); if (val.replace(/\D/g, '').length > value.replace(/\D/g, '').length) { value += val.replace(/\D/g, '').slice(value.replace(/\D/g, '').length); } $(this).val(value); return this; } return this.each(function() { $(this).on('load keyup paste', change); $(this).trigger('load'); }); } }); $(".phone").phone(); $(".phone").on("change", function() { console.log("change"); }) $(".no_phone").on("change", function() { console.log("change"); }) <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="phone" value="+380000000000"> <input type="text" class="no_phone" value="123">Ps Solo abierto en safari.
Esto no funciona solo para el campo en el que se cuelga esta función. Otro campo normalmente cumple con el cambio.
IOS tiende a no disparar eventos de cambio cuando cambia el valor de sus entradas.
Si cambia onchange a onblur , funciona para iOS pero no para otros. La solución a la que finalmente llegué fue usar AMBOS onblur y onchange . Parece redundante pero tiene el efecto deseado.
$(".phone").on("change blur", function() { console.log("change"); })