开发时遇到的 bug,记住密码后在填充用户名和密码时,密码框填充正常,原本用户名的 input框未正常填充,反而填充到了关键词的 input框。百度后找到解决方案,在此记录。
前提:元素绑定方法和双向绑定数据均无问题。
解决方案:
1.在原 input框后新增一个 password属性的 input框,并添加 autocomplete="new-password"属性,隐藏元素;
2.原 input框添加 autocomplete="off " 属性。
注:直接给原input框加 autocomplete="off " 属性没有作用
<!-- 原关键词输入框 -->
<input type="text" placeholder="请输入关键词" ng-keyup='index.searchmethod($event)' ng-model="search.keywords"/>
<!-- 调整后 -->
<input type="text" autocomplete="off" placeholder="请输入关键词" ng-keyup='index.searchmethod($event)' ng-model="search.keywords"/>
<!-- 解决记住密码后关键词输入框会自动填充用户名的问题 -->
<input type="password" autocomplete="new-password" style="display: none"/>