2018年6月15日 星期五

利用 autocomplete attribute 來使用自動儲存的資料

如果有看 Chrome Console 的話,就會注意到當你有表單時,有時會出現如下的警告訊息
[DOM] Input elements should have autocomplete attributes (suggested: "current-password"): (More info: https://goo.gl/9p2vKq)
This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see https://goo.gl/zmWq3m.

根據他所給的連結(Create Amazing Password Forms)和W3C的 Autofilling form controls: the autocomplete attribute 這篇文章,可以知道 autocomplete attribute 可以有多種參數可用

例如登入表單,帳號欄位就可以是 <input name="account" autocomplete="username"/>  ;忘記密碼表單的新密碼欄位可以是 <input name="new-password" type="password" autocomplete="new-password"/>  ……

至於 autocomplete 有哪些值可以用,W3C 的《Autofilling form controls: the autocomplete attribute》都有列了,就不多寫一遍了

PS: 這件事其實幾年前我就知道了,可是就是懶得筆記

PS2: 其實這資訊很實用,可為什麼像 W3Schools 這些教學網站都沒說啊?

沒有留言:

張貼留言