我的js代码实现邮箱的验证,目前的功能没有写完,但是老是出现错误,请求大侠们指点指点,
<head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/><styletype="t...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
.jstest{
width:300px;
height:200px;
background-color:#CCCCCC;
text-align:center;
}
</style>
<script type="text/javascript">
function check()
{
var obj=document.getElementById("email")
if(obj.value!="")
{
var str= obj.value
if(str.indexof("@")!=-1){
}
else{
//document.getElementById("mess").innerText"输入错
误"
document.getElementById("mess").innerHTML="<font
color='red'>输入错误</font>"
}
}
else{
}
}
</script>
<title>无标题文档</title>
</head>
<body>
<label> email验证</label>
<input type="text" id="email"/>
<input type="button" value="验证" onclick="check()"/>
<span id="mess"></span>
</body>
</html> 展开
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
.jstest{
width:300px;
height:200px;
background-color:#CCCCCC;
text-align:center;
}
</style>
<script type="text/javascript">
function check()
{
var obj=document.getElementById("email")
if(obj.value!="")
{
var str= obj.value
if(str.indexof("@")!=-1){
}
else{
//document.getElementById("mess").innerText"输入错
误"
document.getElementById("mess").innerHTML="<font
color='red'>输入错误</font>"
}
}
else{
}
}
</script>
<title>无标题文档</title>
</head>
<body>
<label> email验证</label>
<input type="text" id="email"/>
<input type="button" value="验证" onclick="check()"/>
<span id="mess"></span>
</body>
</html> 展开
2个回答
展开全部
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>价格录入限定</title>
<style type="text/css">
.jstest{
width:300px;
height:200px;
background-color:#CCCCCC;
text-align:center;
}
</style>
<script type="text/javascript">
function check()
{
var obj=document.getElementById("email")
if(obj.value!=""){
var str= obj.value;
if(str.indexOf("@")!=-1){ //这里的indexof的of的o应该是大写
if(str.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)){
document.getElementById("mess").innerHTML="<font color='green'>正确</font>"
}else{
document.getElementById("mess").innerHTML="<font color='red'>格式不正确</font>"
}
}else{
document.getElementById("mess").innerHTML="<font color='red'>输入错误</font>"
}
}else{
document.getElementById("mess").innerHTML="<font color='red'>无输入</font>"
}
}
</script>
</head>
<body>
<label> email验证</label>
<input type="text" id="email"/>
<input type="button" value="验证" onclick="check()"/>
<span id="mess"></span>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询