帮我改改下面这段js表单验证,输入10个字符就知道有什么毛病了
他会增加一堆提示信息,怎么让他只增加一次验证信息...帮我改一下<html><head><metahttp-equiv="Content-Type"content="te...
他会增加一堆 提示信息,怎么让他只增加一次验证信息...帮我改一下
<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;
document.getElementsByName('a')[0].appendChild(newElement);
//return false;
}
}
</script>
<form name=a ">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6" id='dd' onkeyup="test(this.innerHTML,'dd',5)"></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;
document.getElementsByName('a')[0].appendChild(newElement);
//return false;
}
}
</script>
<form name=a ">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6" id='dd' onkeyup="test(this.innerHTML,'dd',5)"></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,
newElement;
idnode=document.getElementById(id);
if(idnode.value.length>len)
{
//判断是否已生成提示
if(document.getElementById('errorMsg')) {
newElement = document.getElementById('errorMsg');
newElement.innerHTML= '输入字数超过最大值'+len;
} else {
newElement = document.createElement('span');
newElement.id = 'errorMsg';
newElement.innerHTML= '输入字数超过最大值'+len;
document.getElementsByName('a')[0].appendChild(newElement);
}
//return false;
}
}
</script>
<form name=a ">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6" id='dd' onkeyup="test(this.innerHTML,'dd',5)"></textarea>
<input type="submit" name="Submit" value="check" >
</form>
</body>
</html>
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>
<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>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询