比如我限制只能输入2位数数字,输入第三位的时候就无效了,仍旧显示之前输入的2个数字,完整点的代码段谁有,谢了~
JSPæ§å¶è¾å
¥æ¡å
æåé¿åº¦é¿åº¦æ¯æ ¹æ®maxlengthå±æ§çéå®ã
ææ¬æ¡æ个maxlengthçå±æ§. å¯éå¶ææ¬æ¡å è¾å ¥çå符é¿åº¦
å¦:
<input type='text' name='id' maxlength='5' />
表示该ææ¬æ¡æå¤å¯è¾å ¥5个å符
ææ¬æ¡æ个maxlengthçå±æ§. å¯éå¶ææ¬æ¡å è¾å ¥çå符é¿åº¦
å¦:
<input type='text' name='id' maxlength='5' />
表示该ææ¬æ¡æå¤å¯è¾å ¥5个å符
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2016-10-14
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function checkNumbers(){
var number = document.getElementById("numbers").value;
var text = null;
if(!number.match("^[0-9]{2}$")){
text = number.substr(0,2);
document.getElementById("numbers").value=text;
}
}
</script>
</head>
<body>
<center>
<form id="form1" name="form1" method="post" action="" >
<label>
<br />
<h1>Please input the numbers:
<input type="text" name="numbers" id="numbers" /></h1>
<br />
<br /><h1>
<input type="button" name="button" id="button" value="提交" onclick="checkNumbers();"/>
</label>
<label>
<input type="reset" name="reset" id="reset" value="重置" />
</label></h1>
</form>
</center>
</body>
</html>本回答被提问者采纳
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function checkNumbers(){
var number = document.getElementById("numbers").value;
var text = null;
if(!number.match("^[0-9]{2}$")){
text = number.substr(0,2);
document.getElementById("numbers").value=text;
}
}
</script>
</head>
<body>
<center>
<form id="form1" name="form1" method="post" action="" >
<label>
<br />
<h1>Please input the numbers:
<input type="text" name="numbers" id="numbers" /></h1>
<br />
<br /><h1>
<input type="button" name="button" id="button" value="提交" onclick="checkNumbers();"/>
</label>
<label>
<input type="reset" name="reset" id="reset" value="重置" />
</label></h1>
</form>
</center>
</body>
</html>本回答被提问者采纳
第2个回答 2009-09-05
<input name="textfield" type="text" maxlength="2" />