jquery - 使用 jQuery css 更改自动填充生成的颜色

标签 jquery html css

我想使用 jQuery 的 css 函数来改变我的电子邮件输入框的颜色

<input type="email" name="email" value="" id="duplicate_email" />

只是改变颜色

jQuery('#duplicate_email').css('color', 'red', 'important');

不起作用,因为自动填充优先

input:-webkit-autofill {
    -webkit-text-fill-color: black;
}

我试图关闭自动完成功能,但这在 chrome 中不再有效

<input type="email" name="email" value="" id="duplicate_email" autocomplete="off" />

我在 jQuery 文档中看到

As of jQuery 1.8, the .css() setter will automatically take care of prefixing the property name. For example, take .css( "user-select", "none" ) in Chrome/Safari will set it as -webkit-user-select, Firefox will use -moz-user-select, and IE10 will use -ms-user-select.

所以我试过了

jQuery('input["email"]:-webkit-autofill').css('text-fill-color', 'red !important');

但哪儿也去不了。

我哪里错了?

最佳答案

您是否尝试过使用 CSS 而不是 jQuery 来修改自动填充的 CSS?

#MyInput:-webkit-autofill {
  -webkit-text-fill-color: black;
  color: black;
  background-color: blue;  
}
<input type='text' placeholder='Autofill Me' id='MyInput' />

如果您想使用 jQuery 来定位要更改的元素,只需在具有特定类名的 CSS 中执行此操作,然后将该特定类名分配给您的 jQuery 选择的元素。

$("#duplicate_email").addClass("Alternative-Autofill");
.Alternative-Autofill:-webkit-autofill {
  -webkit-text-fill-color: black;
  color: black;
}

关于jquery - 使用 jQuery css 更改自动填充生成的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35466386/

相关文章:

jquery - 使用 jQuery .load 将行添加到 html 表

html - Thymeleaf - 如何在 Thymeleaf 标签 "th:if"中将字符串与 html 中的请求参数进行比较?

javascript - 我想在我的选择标签中显示选择性别作为占位符

javascript - 手机间隙 : How to save a HTML5 canvas as image to device photo gallery/library

html - 封面背景图片与 IE 不兼容,试图找到可行的替代方案

css - 垂直对齐内容 slickslider

javascript - 在 Jquery 中删除类时使用多个选择器

asp.net - 如何检查文件是否准备好?

javascript - 在 Firefox 中调整大小不起作用

css - 在 GWT 应用程序中包含谷歌字体的正确方法