在此页面上,当页面加载时,我重置所有输入框的值,并将focus
打开到第一个输入框,例如user-name
。但是,在这里,有些不需要的文本会出现在dwd
框上的user-name
以及页面加载时的密码字段中。每当页面加载时,placeholder
都不会出现。这里的错误是什么?请看图像
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
</head>
<body>
<form name="loginForm" method="post">
<input type="text" name="user-name" placeholder="Firstname Lastname"/><br/>
<input type="password" name="password" placeholder="Password"/><br/>
<input type="password" name="password1" placeholder="Confirm password"/><br/>
<input type="email" name="email" placeholder="Email" required/><br/>
<input type="url" name="url" placeholder="Website"/><br/>
<input name="submit" type="submit" value="Submit"/>
</form>
<script type="text/javascript">
window.onload = function(){
document.getElementsByName("user-name")[0].value="";
document.getElementsByName("password")[0].value="";
document.getElementsByName("password1")[0].value="";
document.getElementsByName("email")[0].value="";
document.getElementsByName("url")[0].value="";
document.getElementById("FormSubmit").style.display="none";
document.getElementsByName("user-name")[0].focus();
}
var formElem = document.getElementsByName("loginForm")[0];
formElem.onsubmit = function(){
var returnValue=true;
if (loginForm["user-name"].value.length < 6 ){
returnValue = false;
alert("dshddhhdhdhh");
return returnValue;
}
}</script>
</body>
</html>