javascript文本验证
这个代码有什么错?我正在检查长度,以确保它在3到5个字符之间javascript文本验证,javascript,validation,Javascript,Validation,这个代码有什么错?我正在检查长度,以确保它在3到5个字符之间 <!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="Co
<!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>Untitled Document</title>
</head>
<body>
<form name = "form1" id="form1">
<input type="text" name="text1" id="text1" value="" onblur="testText(3,5)" />
</form>
<script type="text/javascript">
function testText(minNum,maxNum){
var str = document.form1.text1.value.length;
if(str >= minNum && str <= maxNum){
alert('valid');
}else{
ALERT('ERROR: \N REQUIRED LENGTH IS AT LEAST' + minNum);
document.form1.text1.focus();
}
}
</script>
</body>
</html>
无标题文件
函数testText(minNum、maxNum){
var str=document.form1.text1.value.length;
如果(str>=minNum&&strALERT()
不是JavaScript函数。ALERT()
是。那么?你使用什么浏览器?有什么问题吗?应该会弹出一个关于输入文本是否有效的警报。我正在使用chrome。哦,哈哈。不知道它是区分大小写的:p谢谢!@suddnely\meALERT('something'))
提供给我未捕获引用错误:在Chrome中未定义警报。@droidus为了将来的调试参考,Chrome有一个JavaScript错误控制台,它会给你一条有用的错误消息。谢谢!抱歉,Chrome和JavaScript是新手!