【问题标题】:Change chrome autofill yellow with this jquery使用此 jquery 更改 chrome 自动填充黄色
【发布时间】:2016-01-31 19:20:44
【问题描述】:

我很想在我的网站上让它为我工作,但这是不可能的..我认为我做错了什么..

我在他的网站上发布了来自 BenjaminMiles 的这个 jquery 代码:

<script>
	if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
		$(window).load(function(){
			$('input:-webkit-autofill').each(function(){
				var text = $(this).val();
				var name = $(this).attr('name');
				$(this).after(this.outerHTML).remove();
				$('input[name=' + name + ']').val(text);
			});
		});
	}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" name="text" />

但仍然不起作用...也尝试了 box-shadow 技巧,但对我不起作用,因为我正在使用带有背景图像的输入。

我在body标签里面有上面的代码,所以..我做错了什么?

【问题讨论】:

    标签: javascript jquery html css google-chrome


    【解决方案1】:

    您可能不需要 jQuery。使用transition 使黄色背景消失。您所要做的就是:

     input:-webkit-autofill,
     input:-webkit-autofill:hover,
     input:-webkit-autofill:focus,
     input:-webkit-autofill:active {
            transition: background-color 5000s ease-in-out 0s;
        }
    

    要更改文本颜色,请添加

    -webkit-text-fill-color: white !important;
    

    用您选择的颜色替换white

    【讨论】:

      【解决方案2】:

      vyastech 修复很好,但您应该使用过渡的“延迟”来代替“持续时间”

      input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
        transition: background-color 0s 3600s;
      }
      

      【讨论】:

        【解决方案3】:

        下面的代码可以工作

            // Change the white to any color ;)
        input:-webkit-autofill {
            -webkit-box-shadow: 0 0 0px 1000px white inset;
        }
        

        您可以尝试使用以下代码更改文本颜色:

           -webkit-text-fill-color: yellow !important;
        

        在下面的代码中使用 jquery 将起作用

            if ($.browser.webkit) {
            $('input[name="password"]').attr('autocomplete', 'off');
        }
        

        【讨论】:

        • 关闭自动完成功能根本不是最好的主意
        猜你喜欢
        • 2014-12-13
        • 2017-06-11
        • 2011-02-24
        • 2016-05-29
        • 2021-06-04
        • 2016-11-21
        • 2016-08-31
        相关资源
        最近更新 更多