我遇到此问题,我无法清除登录页面的文本框。当用户成功登录然后立即返回登录页面时,他仍会在文本框中看到他的用户名和密码。
我尝试使用此代码来解决问题
body onload="document.getElementById('name').value='';document.getElementById('pass').value=''"
但是这段代码的问题是它没有立即清除文本框。我需要在它工作之前刷新页面几次。有没有其他方法可以解决问题?
这是我的代码
<?php
/**** Start Session ****/
session_start();
/**** Deletes the data stored in the session ****/
unset($_SESSION['SESS_USER_NAME']);
unset($_SESSION['REF_ID']);
unset($_SESSION['REF_FNAME']);
unset($_SESSION['REF_LNAME']);
unset($_SESSION['REF_ACCOUNT']);
unset($_SESSION['COUNT']);
?>
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
</head>
<body onload="document.getElementById('name').value='';document.getElementById('pass').value=''">
<form action="admin-exec.php" method="post" >
<center><?php include('../function/admin_errmsg.php'); ?></center>
<br>
<input type="text" name="txt_username" placeholder="Username" id="name">
<br>
<input type="password" name="txt_password" placeholder="Password" id="pass">
<br>
<img id="captcha" class="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" />
<input type="text" name="captcha_code" size="10" maxlength="6" placeholder="Input Captcha Code Here" />
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">
<br />[ Different Image ]</a>
<br>
<br>
<input type="submit" value="Let Me In" class="btn" >
</form>
</body>
</html>
答案 0 :(得分:1)
我怀疑浏览器会自动填充字段,因为代码中没有任何内容可以填充输入值。
从UX的角度来看,虽然我希望它在登录后重定向到另一个页面,或者如果它是标题中的登录表单,我希望它不再显示。
答案 1 :(得分:0)
将以下代码用于html部分
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<script>
function clearAll()
{
document.getElementById('name').value='';
document.getElementById('pass').value='';
}
</script>
</head>
<body onload="clearAll()">
<form action="admin-exec.php" method="post" >
<center><?php include('../function/admin_errmsg.php'); ?></center>
<br>
<input type="text" name="txt_username" placeholder="Username" id="name">
<br>
<input type="password" name="txt_password" placeholder="Password" id="pass">
<br>
<img id="captcha" class="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" />
<input type="text" name="captcha_code" size="10" maxlength="6" placeholder="Input Captcha Code Here" />
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">
<br />[ Different Image ]</a>
<br>
<br>
<input type="submit" value="Let Me In" class="btn" >
</form>
</body>
</html>
答案 2 :(得分:0)
你可以像这样添加和javascript
$(document).ready(function(){
$("#name").val("");
)