网站的简单表格验证(Javascript / Css / Html)

时间:2017-05-08 20:44:28

标签: javascript html css

我有一个简单的表格:

<div class = "container">
<img src = "images/login.png">
<form name = "myForm">
<div class = "form-input">
<input type = "text" name = "username" id="username"
placeholder="Enter Username">
</div>
<div class = "form-input">
<input type = "password" name = "password" id="password"
placeholder="Enter Password">
</div>
<input type = "Submit" name = "Submit" value = "LOGIN" class = "login-form">

我正在尝试JavaScript以使表单具有简单的验证,以检查用户名框是否为空,但它不起作用:

<script>  
function validateform(){  
var x = document.forms["myForm"]["username"].value;
if(x == null || x == ""){
alert("Please include a username");
return false;
}
}
</script>

有什么问题?是我的语法还是命名?我的表格和名称是正确的使用变量,我不知道我做错了什么。

0 个答案:

没有答案