解决input 中text="password"时,浏览器会记住之前的用户名和密码问题

原代码:

<label for="username" class="sub-title">用户名:</label> 
<input type="text" id="username" class="sub-input" placeholder="123" autocomplete="off"><br />
<label for="pwd" class="sub-title">密码:</label>
<input type="password" id="pwd" class="sub-input" placeholder="****" autocomplete="off"><br />

原样式:
在这里插入图片描述
实际我希望的情况是和路径那样,可是浏览器记录了之前输入过的账户和密码,由于用了bootstrap或layui的插件,所以出现刷新后样式不一致的问题,丑爆了
解决方法:
在text="password"的input标签上加上下面这句

autocomplete="new-password"
<label for="username" class="sub-title">用户名:</label> 
<input type="text" id="username" class="sub-input" placeholder="123" autocomplete="off"><br />
<label for="pwd" class="sub-title">密码:</label>
<input type="password" id="pwd" class="sub-input" placeholder="****" autocomplete="new-password"><br />

再次打开后样式:
在这里插入图片描述

完美!

猜你喜欢

转载自blog.csdn.net/weixin_40626699/article/details/85100813
今日推荐