0

我有一个登录和注册表单,当我加载我的注册表单时,我的最后一个登录用户名和密码已预先填充在我的 2 个不相关的字段中。我尝试清除浏览器缓存、历史记录、更改字段的 ID,但没有帮助。它预先填充在我的邮政编码和密码字段中。如果我删除这两个字段中的任何一个,其他字段就会成为受害者。有谁知道是什么问题?它只发生在 Chrome 中。谢谢。

<fieldset id="inputs">
                        <asp:TextBox ID="username" CssClass="username" placeholder="Username" required runat="server" />
                        <asp:RequiredFieldValidator ID="UsernameRequired" runat="server" ControlToValidate="username" 
                                                    CssClass="failureNotification" Display="Dynamic" ErrorMessage="UserName is required." ToolTip="UserName is required." 
                                                    ValidationGroup="RegisterUserValidationGroup"  >*</asp:RequiredFieldValidator>
                        <asp:TextBox ID="email" CssClass="email" placeholder="Email" required runat="server" />    
                        <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="email" 
                                                    CssClass="failureNotification" Display="Dynamic" ErrorMessage="Email is required." ToolTip="Email is required." 
                                                    ValidationGroup="RegisterUserValidationGroup"  >*</asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator CssClass="failureNotification"
                                                        ID="EmailExpression" runat="server" ErrorMessage="Invalid Email Format." 
                                                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="email" Display="Dynamic" ToolTip="Email format is invalid."
                                                        ValidationGroup="RegisterUserValidationGroup">!</asp:RegularExpressionValidator> 
                        <asp:TextBox ID="Zipcode" CssClass="Zipcode" placeholder="Zip / Postal Code" required runat="server" />  
                        <asp:RequiredFieldValidator ID="ZipcodeRequired" runat="server" ControlToValidate="Zipcode" 
                                                    CssClass="failureNotification" Display="Dynamic" ErrorMessage="Postal Code is required." ToolTip="Postal Code is required." 
                                                    ValidationGroup="RegisterUserValidationGroup"  >*</asp:RequiredFieldValidator>  
                        <asp:CustomValidator ID="ctvLastVisitDuration" runat="server" ClientValidationFunction="calculateCoordinates"
                                             ControlToValidate="Zipcode" ErrorMessage="Unable to locate address!"
                                             Display="Dynamic" 
                                             ValidationGroup="RegisterUserValidationGroup"></asp:CustomValidator>

                        <asp:TextBox ID="password" CssClass="password" TextMode="Password" placeholder="Password" required
                                     AssociatedControlID="Password" runat="server" />
                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" 
                                                    SetFocusOnError="true" CssClass="failureNotification" Display="Dynamic" 
                                                    ValidationGroup="RegisterUserValidationGroup" ToolTip="Password is required.">*</asp:RequiredFieldValidator>
                        <asp:TextBox ID="ConfirmPassword" CssClass="password" TextMode="Password" placeholder="Comfirm Password" required
                                     AssociatedControlID="Password"  runat="server" />
                        <asp:RequiredFieldValidator ControlToValidate="ConfirmPassword" CssClass="failureNotification" Display="Dynamic" 
                                                    ErrorMessage="Confirm Password is required." ID="ConfirmPasswordRequired" runat="server" 
                                                    ToolTip="Confirm Password is required."
                                                    ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
                        <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" 
                                              CssClass="failureNotification" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                                              ValidationGroup="RegisterUserValidationGroup" >!</asp:CompareValidator>
                    </fieldset>
4

1 回答 1

1

TextBox 具有 AutoCompleteType="None" 属性,但我总是使用 javascript:

function removeAutoComplete(){
   $('input:[type="text"]').each(function(){this.autocomplete='off';});   
}

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(removeAutoComplete);

或者

$(document).ready(function(){removeAutoComplete();});

您也可以通过 id 或 class 在带有 jquery 的页面上找到您的文本框。

$('input:[type="text"]:[id="inputId"]')  
$('input:[type="text"]:[class="inputClass"]')
于 2012-11-30T07:41:47.497 回答