谷歌浏览器记住密码输入框颜色会改变,而且字体颜色会变成黑色,如图css
输入框原来的样式是这样的
![]
然而记住密码后,输入框颜色就变成了黄色,而且字体变成了黑色
这是因为谷歌浏览器的自带样式的缘故:web
input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {chrome
background-color: rgb(250, 255, 189);浏览器
background-image: none;字体
color: rgb(0, 0, 0);this
}spa
若是咱们想记住密码后仍然想要之前的颜色,能够用 设置input内阴影 的方式把黄色覆盖掉,css代码:设计
input:-webkit-autofill{orm
-webkit-box-shadow: 0 0 0 400px #E8ECED inset;blog
}
这样输入框就变成了
然而字体仍然是黑色的,若是想改变字体,则
input:-webkit-autofill{
-webkit-box-shadow: 0 0 0 400px #E8ECED inset;
-webkit-text-fill-color: #666666;//设置字体颜色
}
屏蔽谷歌浏览器记住表单密码
解决谷歌浏览器表单记住密码引发的各类bug,记住密码后输入框看似有值,但使用js表单验证的时候却获取不到值,为了解决这个问题须要屏蔽浏览器的默认记住密码这一共能,代码以下:
<input id="loginname" type="text" placeholder="手机号" autocomplete="off">
<input id="passwd" type="password" placeholder="密码" autocomplete="off">
<script>
$('#passwd').attr('type','text').focus(function(){
$(this).attr('type','password');
});
</script>
问题所在:
谷歌浏览器会自动填充密码,某方面是很方便,可是也会出现意想不到的效果,好比填充的颜色变成黄色,可能与设计不符,主要缘由是浏览器给input加上了一个样式:
input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill { background-color: rgb(250, 255, 189); background-image: none; color: rgb(0, 0, 0); }
解决方法其一能够是覆盖浏览器的样式。但,咱们能够尝试更加高大上的解决办法:
解决办法:
在旧版的谷歌浏览器中,可使用如下方法:
<form autocomplete="off">
对于整个表单生效;
<input autocomplete="off">
对于单个input生效;
在新版的谷歌浏览器中,autocomplete=”off”已经失效,须要尝试如下方法:
<!-- fake fields are a workaround for chrome autofill getting the wrong fields --> <input style="display:none" type="text" name="fakeusernameremembered"/> <input style="display:none" type="password" name="fakepasswordremembered"/>
用法是在form表单的加入这两句代码,而后name须要改为将要禁止填充的input。其原理是,谷歌浏览器会自动填充这个input,而不会填充你代码中实际展现的input,从而绕过谷歌浏览器的自动填充功能;
(注:看别的内容记录下来)