//取文本输入框的实际长度
String.prototype.JLen = function()
{return this.replace(/[^/x00-/xff]/g, "AA").length;}
//判断文本输入框输入内容实际长度是否满足MaxLength
function CheckRealLength()
{
var realLength; //文本框中内容的实际长度
var maxLength; //要求的最大长度
var list = document.getElementsByTagName("input"); //获取表单并付给数组
for (var i = 0 ; i < list.length ; i++)
{
if (list[i].Field != null)
{
realLength = list[i].value.JLen();
if (realLength > 0)
{
//alert(list[i].Field);
maxLength = list[i].maxLength;
//alert(realLength + "+" + maxLength);
if (realLength > maxLength)
{
alert("温馨提示:您输入的字符串长度(" + realLength + ")应该小于" + maxLength + "(中文全角字符占两位)!");
list[i].focus();
return false;
}
}
}
}
}
****************prototype ****************************
返回对象类型原型的引用。
objectName.prototype
objectName 参数是对象的名称。
说明
用 prototype 属性提供对象的类的一组基本功能。 对象的新实例“继承”赋予该对象原型的操作。 例如,要为 Array 对象添加返回数组中最大元素值的方法。 要完成这一点,声明该函数,将它加入 Array.prototype, 并使用它。
function array_max( ){
var i, max = this[0];
for (i = 1; i < this.length; i++)
{
if (max < this[i])
max = this[i];
}
return max;
}
Array.prototype.max = array_max;
var x = new Array(1, 2, 3, 4, 5, 6);
var y = x.max( );
该代码执行后,y 保存数组 x 中的最大值,或说 6。