密码输入元素问题

时间:2011-03-30 22:14:41

标签: php html

我有一个用于登录过程的密码元素。但是,一旦页面打开,我会得到这个奇怪的用户名和密码!!

enter image description here

但问题是当我没有用户密码元素但只输入我没有得到这个奇怪的用户名和密码时,我该怎么办才能让它们变成空白?

这是代码

    echo"
    <center><small>
    <br />
    &nbsp; &nbsp;
    <p> Welcome Guest you can sign in here:</p></br>
    <form action = \"HomeWork.php\" method = \"post\">
    User name*: <input type=\"text\" name=\"Username\" />
    Password*: <input type=\"password\" name=\"Password\" />&nbsp;

<a href=\"Signup.php\">or Sign up !</a>
        <br /> <br />
        <input type=submit value=Submit align=\"middle\" />
        </form>
        </small></center>";
你能帮帮我吗?

4 个答案:

答案 0 :(得分:5)

这是您的浏览器,记住您为localhost网站输入的用户名/密码。这与你的html或php无关。要进行测试,请在另一个用于查看localhost站点的浏览器中进行测试,看看它是否将其添加到表单元素中。

修改

请注意,根据kag的回答,您可以在表单中添加autocomplete=off,以防止浏览器自动填充。

https://developer.mozilla.org/en/how_to_turn_off_form_autocompletion

echo "
<center>
 <small>
  <br />
  &nbsp;
  <p>Welcome Guest you can sign in here:</p></br>
  <form action='HomeWork.php' method='post' autocomplete='off'>
   Username*: <input type='text' name='Username' />
   Password*: <input type='password' name='Password' />&nbsp;
   <a href='Signup.php'>or Sign up !</a>
   <br />
   <input type='submit' value='Submit' align='middle' />
  </form>
 </small>
</center>
";

另外,请考虑不要使用centersmall等标签;而是使用css和classes / selectors。

答案 1 :(得分:3)

这是您的浏览器尝试通过自动为您填写字段来帮助您。如果您想阻止它这样做,您可以在autocomplete="off"中添加<input>

答案 2 :(得分:1)

尝试将“value”属性添加到输入标记并将其设置为空:

<input type="text" name="Username" value="" />

如果没有,请尝试使用javascript:

<head>
    <script type="text/javascript">
        function clearMyFields() {
            document.getElementById('input_u').value = "";
            document.getElementById('input_p').value = "";
        }
    </script>
</head>
<body onload="clearMyFields();">
    <input type="text" id="input_u" name="Username" value="" />
    <input type="password" id="input_p" name="Password" value="" />

答案 3 :(得分:0)

尝试:

<meta http-equiv="Pragma" content="no-cache">

<!-- Pragma content set to no-cache tells the browser not to cache the page
This may or may not work in IE -->

<meta http-equiv="expires" content="0">

<!-- Setting the page to expire at 0 means the page is immediately expired
Any vales less then one will set the page to expire some time in past and
not be cached. This may not work with Navigator -->