我想使用 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/