首页 文章

使用先前输入的值阻止文本框自动填充

提问于
浏览
38

我有一个带有一些Textbox控件的asp页面 .

默认情况下,浏览器会建议先前为每个框输入的值 .

我想阻止某些文本框的行为 .

有没有办法在所有主流浏览器中可靠地做到这一点?

我试过设定

AutoCompleteType="Disabled"

但这似乎对Firefox没有影响 .

这是我试图阻止的行为的图像 .

enter image description here

8 回答

  • 3

    对于Firefox

    或者:

    <asp:TextBox id="Textbox1" runat="server" autocomplete="off"></asp:TextBox>
    

    或者从CodeBehind:

    Textbox1.Attributes.Add("autocomplete", "off");
    
  • 0

    自动完成需要从文本框中启动

    <asp:TextBox ID="TextBox1" runat="server" autocomplete="off"></asp:TextBox>
    
  • 0

    这就是答案 .

    <asp:TextBox id="yourtextBoxname" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
    

    AutoCompleteType =“已禁用”

    如果您仍然在Firefox浏览器中获得预先填充的框,那么它的浏览器是错误的 . 你得走了

    '选项' - >'安全'(标签) - >解开

    '记住网站密码,然后单击“保存的密码”按钮删除浏览器保存的所有详细信息 .

    这应该可以解决问题

  • 1

    从CodeBehind尝试:

    Textbox1.Attributes.Add("autocomplete", "off");
    
  • 6

    通过使AutoCompleteType =“禁用”,

    <asp:TextBox runat="server" ID="txt_userid" AutoCompleteType="Disabled"></asp:TextBox>
    

    通过设置autocomplete =“off”,

    <asp:TextBox runat="server" ID="txt_userid" autocomplete="off"></asp:TextBox>
    

    通过设置表单autocomplete =“off”,

    <form id="form1" runat="server" autocomplete="off">  
        //your content  
        </form>
    

    通过在.cs页面中使用代码,

    protected void Page_Load(object sender, EventArgs e)   
        {  
            if (!Page.IsPostBack)  
            {  
                txt_userid.Attributes.Add("autocomplete", "off");  
            }  
        }
    

    使用Jquery

    <head runat = "server" >  
            < title > < /title> < script src = "Scripts/jquery-1.6.4.min.js" > < /script> < script type = "text/javascript" >  
            $(document).ready(function()  
            {  
                $('#txt_userid').attr('autocomplete', 'off');  
            });  
        //document.getElementById("txt_userid").autocomplete = "off"  
        < /script>
    

    这是我的文本框,

    <asp:TextBox runat="server" ID="txt_userid" ></asp:TextBox>
    

    通过在代码中设置文本框属性,

    protected void Page_Load(object sender, EventArgs e)   
        {  
            if (!Page.IsPostBack)  
            {  
                txt_userid.Attributes.Add("autocomplete", "off");  
            }  
        }
    
  • 8

    请注意,要让Chrome正常运行,需要自动填充=“false”

  • 62

    这适合我

    <script type="text/javascript">
            var c = document.getElementById("<%=TextBox1.ClientID %>");
            c.select =
            function (event, ui) 
            { this.value = ""; return false; }
        </script>
    
  • 11

    将autocomplete =“new-password”添加到密码字段就可以了 . 删除了Chrome中用户名和密码字段的自动填写功能 .

相关问题