Make text input fields remember previously entered data

前端 未结 7 1799
夕颜
夕颜 2021-02-18 23:30

My text inputs seem not to remember values that have been typed before. For example, many websites that I don\'t even have an account on, but have, for example entered my email

7条回答
  •  星月不相逢
    2021-02-19 00:20

    some browsers adamantly refused to remember an input until i "remembered it manually" via (ab)using localStorage... this worked for me:

        {
            // hack to remember last error id on page refresh
            // can't believe i have to do this, but my browser don't want to remember it itself, 
            // ... not sure why
            let $=document.querySelector.bind(document);
            let errorid_element=$("#errorlog_id");
            let rememberHack=function(){
                localStorage.setItem("last_id_remember_hack",errorid_element.value);
            };
            errorid_element.addEventListener("input",rememberHack);
            errorid_element.addEventListener("change",rememberHack);
            errorid_element.value = localStorage.getItem("last_id_remember_hack");
        }
    

提交回复
热议问题