简体   繁体   English

如何重置输入自动完成样式?

[英]How do I reset input autocomplete styles?

I have a simple Bootstrap form that is proceeded via JavaScript. 我有一个简单的Bootstrap表单,通过JavaScript进行。 Once the submit button is clicked, it proceeds its data and resets the input values without reloading the page: 单击提交按钮后,它将继续其数据并重置输入值,而无需重新加载页面:

if( json.success ) {
  $('#form_sendemail').find('.form-control').val('');
}

The problem is that if there were any autocompleted form fields (highlighted with yellow in Chrome), they stay highlighted even after the form has been sent and the form fields cleared. 问题是,如果有任何自动填充的表单字段(在Chrome中以黄色突出显示),即使在表单已发送并且表单字段已清除后,它们仍会保持突出显示。 How do I reset those styles without reloading the page? 如何在不重新加载页面的情况下重置这些样式? (setting background-color to !important didn't help). (将background-color设置为!important没有帮助)。

在此输入图像描述

Try out the reset function: 尝试重置功能:

$.ajax({
    //...
    success: function (data, status) {
        document.getElementById('yourFormID').reset();
    }
});

<form id="yourFormID"></form>

EDIT: 编辑:

JQuery (the awesome): JQuery(很棒):

$.ajax({
    //...
    success: function (data, status) {
        $('#yourFormID')[0].reset();
    }
});

You can try this 你可以试试这个

For Chrome 适用于Chrome

input:-webkit-autofill {
    background-color: #FAFFBD !important;
color: #2a2a2a !important;
}

Script 脚本

$("input[type='text']").bind('focus', function() {
   $(this).css('background-color', '#fff');
   $(this).css('color', '#000');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改输入容器的样式 - How do I change the styles of the input container 如何重设某个div的所有CSS样式? (Jekyll博客) - How do I reset all css styles for a certain div? (Jekyll blog) 如何在 React 中的“Enter”keyUp 上重置输入字段? - How do I reset an input field on 'Enter' keyUp in React? 每次输入后如何重置列表? - How do I reset the list after each input? 如何重新加载页面时如何重置文本输入的值? - How do I reset the value of a text input when the page reloads? 如何将自动完成功能与地理编码相结合以获取纬度。 &amp;液化天然气。 从这个自动完成功能中的表单输入? - how do I combine autocomplete with geocode to get Lat. & Lng. from form input in this autocomplete function? 提交后如何让我的自动完成输入字段重置 DefaultValue? - How to get my Autocomplete input field to reset DefaultValue after submit? 如何重置Highcharts中为系列提供的样式? - How can I reset the styles given to series in Highcharts? 如何使用输入进行自动完成搜索? - how to do autocomplete search working with input? 我们如何将输入类型设置为 Reset 并在 Reset 上设置 Click 事件 - How do we give input type as Reset and a Click event on Reset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM