日期:2014-05-16 浏览次数:20394 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
.test{width:400px;height:30px;margin:100px auto;}
input{padding:5px 0 5px 5px;float:left; width:198px;background:none;border:solid 1px #ccc;height:20px;}
.test span{float:left;font-size:12px;height:30px;line-height:30px; padding-left:10px;}
.awokeW{color:red;}
.awokeR{color:green;}
</style>
<script>
window.onload=function()
{
var oInput=document.getElementById('username');
var oSpan=document.getElementById('awoke');
oInput.onkeyup=function()
{
if(/^\w{6,10}$/g.test(this.value))
{
oSpan.className='awokeR';
oSpan.innerHTML='填写正确';
}
else
{
oSpan.className='awokeW';
oSpan.innerHTML='请确保填写内容在6-10个字符';
}
}
}
</script>
</head>
<body>
<div class="test">
<input type="text" id="username" name="username" />
<span class="awokeW" id="awoke"></span>
</div>
</body>
</html>