javascript表单验证码怎么写
发布网友
发布时间:2022-05-01 10:24
我来回答
共2个回答
热心网友
时间:2022-04-22 15:17
我来举个例子,很简单的
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function formCheck(){//表单验证
var userForm=document.forms.userForm;
if(userForm.username.value==null||userForm.username.value.length<=0){
alert("用户名不能为空");
return false;
}else if(userForm.username.value.length<6||userForm.username.value.length>20){
alert("用户名必须为6-20位");
return false;
}else if(userForm.password.value==null||userForm.password.value.length<=0){
alert("密码不能为空");
return false;;
}else if(userForm.password.value.length<6||userForm.password.value.length>20){
alert("密码必须为6-20位");
return false;
}else{
userForm.submit();
}
}
</script>
</head>
<body>
<form action="" name="userForm">
userName:<input type="text" name="username"><br>
password:<input type="password" name="password"><br>
<input type="button" value="提交" onclick=" formCheck()">
</form>
</body>
</html>
热心网友
时间:2022-04-22 16:35
验证码javascript是实现不了的,只能使用其他变成语言比如php、。net、jsp等