function inputListener(inputElement, maxLength) { let flag = true; inputElement.on(‘compositionstart‘, function () { flag = false; }); inputElement.on(‘compositionend‘, function () { flag = true; }); inputElement.on(‘input‘, function () { setTimeout(function () { if (flag) { let textnum = inputElement.val().replace(/\s+/g, "").length; $(‘.text-count .count‘).text(textnum); if (textnum < maxLength) { $(‘.text-count .limit‘).text(‘‘); $(‘.text-count .count‘).css(‘color‘, ‘#999‘); } if (textnum === maxLength) { $(‘.text-count .limit‘).text(`您最多只能输入${maxLength}字`); $(‘.text-count .count‘).css(‘color‘, ‘#ff3344‘); } } }, 100); }); }