大家帮我看看下面这段js表单验证为什么什么都不提示?
这个是验证字符长度的<html><head><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"...
这个是验证 字符长度的
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
function test(text,id,len)
{
var idnode;
idnode=document.getElementById(id);
if(idnode.value.length>len)
{
var newElement = document.createElement('span');
newElement.innerHTML= '输入字数超过最大值'+len);
alert(newElement);
document.getElementsByName('a')[0].appendChild(newElement);
//return false;
}
}
</script>
<form name=a onsubmit="return test(this.b,'dd',5)">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6" id='dd'></textarea>
<input type="submit" name="Submit" value="check">
</form>
</body>
</html> 展开
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
function test(text,id,len)
{
var idnode;
idnode=document.getElementById(id);
if(idnode.value.length>len)
{
var newElement = document.createElement('span');
newElement.innerHTML= '输入字数超过最大值'+len);
alert(newElement);
document.getElementsByName('a')[0].appendChild(newElement);
//return false;
}
}
</script>
<form name=a onsubmit="return test(this.b,'dd',5)">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6" id='dd'></textarea>
<input type="submit" name="Submit" value="check">
</form>
</body>
</html> 展开
2个回答
2015-03-02
展开全部
<!DOCTYPE HTML>
<html>
<head>
<title>yugi</title>
<meta charset=UTF-8 />
<style type="text/css">
</style>
<script type="text/javascript">
function test (form, len)
{
var b = form.b;
if (b.value.length > len)
{
tip.innerHTML = '输入字数超过最大值' + len;
return false;
}
return true;
}
</script>
</head>
<body>
<form name="a" onsubmit="return test(this, 5)">
<textarea name="b" cols="40" wrap="hard" rows="6" id='dd'></textarea>
<input type="submit" name="Submit" value="check">
<span id="tip"></span>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询