日期:2014-05-16 浏览次数:20448 次
String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.LTrim = function() { return this.replace(/(^\s*)/g, ""); } String.prototype.RTrim = function() { return this.replace(/(\s*$)/g, ""); } String.prototype.htmlEncode = function() { return this.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """); } String.prototype.htmlDecode = function() { return this.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"'); } //获得字符串长度,将中文转换为两个字符长度 String.prototype.len= function () { return this .replace(/[^\x00-\xff]/g, "rr" ).length; } //截取中英文字符串 String.prototype.sub = function (n) { var r = /[^\x00-\xff]/g; if ( this .replace(r, "mm" ).length <= n) return this ; var m = Math.floor(n/2); for ( var i=m; i< this .length; i++) { if ( this .substr(0, i).replace(r, "mm" ).length>=n) { return this .substr(0, i) + "..." ; } } return this ; }; /×××以上资源非原创,乃网上多出收集而来,方便大家使用·····×××/