JavaScript中为String对象添加 trim / ltrim / rtrim 方法 (2004-09-16)
发布时间 2004-09-16 10:50:00
JavaScript中为String对象添加 trim() 方法
//自己动手为string添加trim
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, "");}
var str = " meizz ";
alert(str.trim());
alert(str.ltrim());
alert(str.rtrim());