【发布时间】:2016-05-29 17:29:36
【问题描述】:
我想用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 文档中看到
从 jQuery 1.8 开始,.css() 设置器将自动处理属性名称的前缀。比如在Chrome/Safari中取.css("user-select", "none")会设置为-webkit-user-select,Firefox会使用-moz-user-select,IE10会使用-ms-user -选择。
所以我尝试了这个
jQuery('input["email"]:-webkit-autofill').css('text-fill-color', 'red !important');
但不去哪里。
我哪里错了?
【问题讨论】:
-
从未涉足过自动完成功能,但您可以尝试切换课程,看看是否会超越它
-
我会创建另一个类,并使用 jQuery 添加该类,而不是修改 css。它使它更清洁,更易于维护
-
我的经验是自动填充优先并覆盖我所做的任何事情。