<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>限制textarea的字符数;允许/阻止文本框中的字符</title>
</head>
<script>
var TextUtil = new Object();
TextUtil.isNotMax = function (oTextArea){
return oTextArea.value.length != oTextArea.getAttribute("maxlength");
}
function blockChars(oTextbox,oEvent){
oEvent = EventUtil.formatEvent(oEvent);
var sInvalidChars = oTextbox.getAttribute("invalidchars");
var chars = String.fromCharCode(oEvent.charCode);
var bIsValidateChar = sInvalidChars.indexOf(chars) == -1;
return bIsValidateChar || oEvent.ctrlKey;
}
</script>
<body>
<!--限制textarea的字符数-->
<textarea rows="10" cols="25" maxlength="10" onkeypress="return TextUtil.isNotMax(this)">
</textarea>
<br>
<!--允许/阻止文本框中的字符-->
<textarea rows="10" cols="25" maxlength="10" type="text" invalidchars="0123456789"
onkeypress="return TextUtil.blockChars(this,event)"></textarea>
</body>
</html>
posted on 2008-05-17 19:42
bcterry 阅读(125)
评论(2) 编辑 收藏