(要求:用户名和text框和报错语句必须在一行)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script>
function check(){
var e,len;
e=doucument.getElementById("un");
len=e.length;
if(len<=6){
span.innerHTML="用户名必须是6个字符以上";
e.focus();
}
else
span.innerHTML="";
}
</script>
</head>
<body>
<form action="">
<p>
用户名:
<input name="username" type="text" value="" size="20" maxlength="20" id="un" onblur="check()"/>
<span></span>
</p>
</form>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script>
function check(){
var span=document.getElementById("span");
var e=document.getElementById("un");
var value=e.value;
var len=value.length;
if(!len||len<=6){
span.innerHTML="用户名必须是6个字符以上";
e.focus();
}
else{
span.innerHTML="";
}
}
</script>
</head>
<body>
<form action="">
<p>
用户名:
<input name="username" type="text" value="" size="20" maxlength="20" id="un" onblur="check()"/>
<span id="span"></span>
</p>
</form>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script>
function check(){
var span=document.getElementById("span");
var e=document.getElementById("un");
var value=e.value;
var len=value.length;
if(!len||len<=6){
span.innerHTML="用户名必须是6个字符以上";
e.focus();
}
else{
span.innerHTML="";
}
}
</script>
</head>
<body>
<form action="">
<p>
用户名:
<input name="username" type="text" value="" size="20" maxlength="20" id="un" onblur="check()"/>
<span id="span"></span>
</p>
</form>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2018-03-26
len = e.innerHTML.length;