简体   繁体   English

HTML表单上不需要的自动填充

[英]Unwanted autofill on html form

I am (for the first time) making a signin/register form for a website. 我(第一次)为网站制作登录/注册表格。 For the line in the register form where I ask the user to provide their email address it provides an autofill option, which is fine. 对于我要求用户提供其电子邮件地址的注册表中的行,它提供了自动填充选项,这很好。 The problem is that it also fills in the line below which is where I will get the user to retype the email address to verify it. 问题在于,它还会在下面的行中填充,我将在该行中让用户重新输入电子邮件地址以进行验证。 I have tried using autocomplete="off" but that does not seem to have an affect. 我尝试使用autocomplete =“ off”,但这似乎没有影响。

I managed to figure out that if the second email input does not have the word "email" in it the autocomplete does not affect this line. 我设法弄清楚,如果第二个电子邮件输入中没有单词“ email”,则自动完成功能不会影响此行。 Still tho, autocomplete="off" had no affect and I don't know why. 还有,autocomplete =“ off”没有影响,我也不知道为什么。 Ideally I would like to have email in the name of this line off code to make it easier to read and similar issues may come up in the future. 理想情况下,我希望以该行代码的名义发送电子邮件,以使其更易于阅读,并且将来可能会出现类似的问题。

Any ideas why this is happening? 任何想法为什么会这样? here is my code: 这是我的代码:

<!DOCTYPE html>
<html5>
    <head>
        <title>Login page</title>
    </head>
    <body>
        <h1>Login or Register</1h>
        <p></p>


        <div id="logindOrRegdiv">
            <input type="button" value="Login" id="login">
            <input type="button" value="Register" id="register">
        </div>

        <div id="logindiv">   
           <form name="login" autocomplete="on">
               Username<input type="text" name="userid"/><br>
               Password<input type="password" name="pswrd"/><br>
               <input type="button" onclick="check(this.form)" value="Login"/>
               <input type="reset" value="Cancel"/>
           </form>
           <script language="javascript">
               function check(form) { /*function to check userid & password*/
                   /*the following code checkes whether the entered userid and password are matching*/
                   if(form.userid.value == "myuserid" && form.pswrd.value == "mypswrd") {
                       window.open('target.html')/*opens the target page while Id & password matches*/
                   }
                   else {
                       alert("Error Password or Username")/*displays error message*/
                   }
               }
           </script>  
        </div>


        <div id="registerdiv">
            <form name="register" autocomplete="on">
                First Name<input type="text" name="firstname"/><br>
                Middle Name<input type="text" name="middlename"/><br> 
                Last Name<input type="text" name="lastname"/><br> 
                D.O.B.<input type="text" name="dob"/><br>
                Email Address<input type="email" name="email"/><br>
                Re-Type<input type="email" name="email2" autocomplete="off"/><br>
                Password<input type="password" name="password"/><br>
                Re-Type<input type="password" name="password2"/><br>
            </form>         
        </div>

        <script src="jquery-1.11.2.js"></script>

        <script src="app.js"></script>
    </body>
</html5>

The autocomplete="off" attrbute has bugs in most major browsers. autocomplete="off"属性在大多数主流浏览器中均存在错误。

http://caniuse.com/#feat=input-autocomplete-onoff http://caniuse.com/#feat=input-autocomplete-onoff

The workaround is to give the name attribute a random value each time the page is loaded. 解决方法是在每次加载页面时为name属性提供一个随机值。 For example name="email-jirbcea" . 例如name="email-jirbcea"

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM