日期:2014-05-16 浏览次数:20359 次
1.JS去掉字符串的最后个字符:
var top=str.substr(0, str.length-1);
?
2.计算字符串长度方法
?//计算字符串长度方法
?var jmz = {}; ?jmz.GetLength = function(str) { ???? ///<summary>获得字符串实际长度,中文2,英文1</summary> ???? ///<param name="str">要获得长度的字符串</param> ???? var realLength = 0, len = str.length, charCode = -1; ???? for (var i = 0; i < len; i++) { ???????? charCode = str.charCodeAt(i); ???????? if (charCode >= 0 && charCode <= 128) realLength += 1; ???????? else realLength += 2; ???? } ???? return realLength; ?}; |