javascript字符類型操做函數

//獲取字符串的長度
String.prototype.getByteLength = function()
{
    var bytes=0,i=0;
    for (; i<this.length; ++i,++bytes) {
        if ( this.charCodeAt(i) > 255 ) {
                ++bytes;
        }
    }
    return bytes;
};
/*函數調用方法*/
var a ="aaa ^&*";
var length = a.getByteLength();
alert(length);
相關文章
相關標籤/搜索