A:for循环检测字符串的字节长度方法一 var lenFor = function(str){ var byteLen=0,len=str.length; if(str){ for(var i=0; i<len; i++){ if(str.charCodeAt(i)>255){ byteLen += 2; } else{ byteLen++; } } return byteLen; } else{ return 0; } } 使用方法 var strlength=lenFor(str)
Read more每日归档: 2012年8月16日
javascript检测函数-字符长度
// Function Name: trim // Function Description: 去除字符串的首尾的空格 // Creation Date: 2004-7-13 15:30 // Last Modify By: N/A // Last Modify Date: N/A String.prototype.trim=function(){ return this.replace(/(^\s*)|(\s*$)/g, “”); } // Function Name: ltrim // Function D
Read more