Detecting Browser Autofill

前端 未结 29 1423
天涯浪人
天涯浪人 2020-11-22 06:15

How do you tell if a browser has auto filled a text-box? Especially with username & password boxes that autofill around page load.

My first question is when does

29条回答
  •  情深已故
    2020-11-22 06:45

    My solution:

    Listen to change events as you would normally, and on the DOM content load, do this:

    setTimeout(function() {
        $('input').each(function() {
            var elem = $(this);
            if (elem.val()) elem.change();
        })
    }, 250);
    

    This will fire the change events for all the fields that aren't empty before the user had a chance to edit them.

提交回复
热议问题