简体   繁体   中英

jquery change function does not work when fill input from cache

I try do form validator using jquery. Generally everything works except one situation.

I want in any change in input my function checkEmail check is everything is ok. If not color of input is change on red. When i write or paste to input it works but when i choose value from cache (browser give me list of value to choose) my input do not change color.

const checkEmail = () => {
if (!validator.isEmail(emailInput.val())) {
    emailInput.removeClass('input-success')
    emailInput.addClass('input-error')
    return false
} else {
    emailInput.removeClass('input-error')
    emailInput.addClass('input-success')
    return true
}

}

emailInput.change('input', checkEmail);

Is any way to trigger a function on really any change? I event try setTimeOut but then it looks like jquery do not see value in my Input.

PS. Im new here please be patience:)

emailInput.on('input', checkEmail);

here the demo https://jsfiddle.net/kt56opsx/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM