js实现用户名和密码的校验
2017-09-15 00:00
489 查看
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
function focus_username(){
var resultObj = document.getElementById("result_username");
resultObj.innerHTML = '请输入你的用户名';
resultObj.style.color = "gray";
}
function blur_username(){
var resultObj = document.getElementById('result_username');
if(document.forml.username.value=='')
{
resultObj.innerHTML = '<font color="red">用户名不能为空!</font>';
}else if(document.forml.username.value.length<5||document.forml.username.value.length>20){
resultObj.innerHTML = '<font color="red">用户名长度必须介于5-20字符串中间!</font>';
}else{
resultObj.innerHTML = '<img src="image/ok.gif">';
}
}
function focus_password(){
var resultObj = document.getElementById("result_password");
resultObj.innerHTML = '请输入你的密码';
resultObj.style.color = "gray";
}
function blur_password(){
var resultObj = document.getElementById('result_password');
if(document.forml.password.value=='')
{
resultObj.innerHTML = '<font color="red">密码不能为空!</font>';
}else if(document.forml.password.value.length<5||document.forml.password.value.length>20){
resultObj.innerHTML = '<font color="red">用户名长度必须介于5-20字符串中间!</font>';
}else{
resultObj.innerHTML = '<img src="image/ok.gif">';
}
}
</script>
</head>
<body>
<form name="forml" method="post" action="login.php">
<table width="600" border="1" bordercolor="#ccc">
<tr>
<td width="100" align="center">用户名:</td>
<td><input type="text" name="username" onfocus="focus_username()" onblur="blur_username()"></td>
<td width="300"><div id="result_username"></div></td>
</tr>
<tr>
<td width="100" align="center">密码:</td>
<td><input type="password" name="password" onfocus="focus_password()" onblur="blur_password()"></td>
<td width="300"><div id="result_password"></div></td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<input type="submit" value="提交表单">
<input type="reset" value="重新填写">
</td>
</tr>
</table>
</form>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
function focus_username(){
var resultObj = document.getElementById("result_username");
resultObj.innerHTML = '请输入你的用户名';
resultObj.style.color = "gray";
}
function blur_username(){
var resultObj = document.getElementById('result_username');
if(document.forml.username.value=='')
{
resultObj.innerHTML = '<font color="red">用户名不能为空!</font>';
}else if(document.forml.username.value.length<5||document.forml.username.value.length>20){
resultObj.innerHTML = '<font color="red">用户名长度必须介于5-20字符串中间!</font>';
}else{
resultObj.innerHTML = '<img src="image/ok.gif">';
}
}
function focus_password(){
var resultObj = document.getElementById("result_password");
resultObj.innerHTML = '请输入你的密码';
resultObj.style.color = "gray";
}
function blur_password(){
var resultObj = document.getElementById('result_password');
if(document.forml.password.value=='')
{
resultObj.innerHTML = '<font color="red">密码不能为空!</font>';
}else if(document.forml.password.value.length<5||document.forml.password.value.length>20){
resultObj.innerHTML = '<font color="red">用户名长度必须介于5-20字符串中间!</font>';
}else{
resultObj.innerHTML = '<img src="image/ok.gif">';
}
}
</script>
</head>
<body>
<form name="forml" method="post" action="login.php">
<table width="600" border="1" bordercolor="#ccc">
<tr>
<td width="100" align="center">用户名:</td>
<td><input type="text" name="username" onfocus="focus_username()" onblur="blur_username()"></td>
<td width="300"><div id="result_username"></div></td>
</tr>
<tr>
<td width="100" align="center">密码:</td>
<td><input type="password" name="password" onfocus="focus_password()" onblur="blur_password()"></td>
<td width="300"><div id="result_password"></div></td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<input type="submit" value="提交表单">
<input type="reset" value="重新填写">
</td>
</tr>
</table>
</form>
</body>
</html>
相关文章推荐
- JS实现用户名,密码正则表达式的校验
- 利用JSP+JS+CSS+Servlet实现用户登录,保存用户名密码功能
- springBoot整合CXF并实现用户名密码校验
- js实现登录用户名和密码只能是数字或字母
- 输入校验一(js实现用户名校验)
- 通过jquery.cookie.js实现记住用户名和密码的功能
- JS中记住用户名 密码的COOKIE实现方式
- springBoot整合CXF并实现用户名密码校验的方法
- JS中记住用户名 密码的COOKIE实现方式
- 通过jquery.cookie.js实现记住用户名、密码登录功能
- JS实现简单的登录界面(不连接数据库,把用户名密码写死)
- JS中记住用户名 密码的COOKIE实现方式
- js 记住 用户名和密码实现也是看的一篇文章。纯js当然我们可以混着jquery使用
- 用JavaScript实现对用户名,密码进行校验
- 登录页面用户名密码的合法性校验,js源码
- js实现密码强度校验
- js实现编辑框用户名 密码 日期选择 按钮提交特效代码
- 浏览器表单验证用户名密码非空的js实现
- 通过jquery.cookie.js实现记住用户名、密码登录功能
- 通过jquery.cookie.js实现记住用户名、密码登录功能