Detecting Browser Autofill

前端 未结 29 1455
天涯浪人
天涯浪人 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:49

    I know this is an old thread but I can imagine many comes to find a solution to this here.

    To do this, you can check if the input(s) has value(s) with:

    $(function() {
        setTimeout(function() {
            if ($("#inputID").val().length > 0) {
                // YOUR CODE
            }
        }, 100);
    });
    

    I use this myself to check for values in my login form when it's loaded to enable the submit button. The code is made for jQuery but is easy to change if needed.

提交回复
热议问题