JS trim

String.prototype.trim = function() { 

    return this.replace(/(^[\s/n]*)|([\s/n]*$)/g, "");

}


String.prototype.ltrim = function() {

    return this.replace(/(^[\s/n]*)/g, "");

}


String.prototype.rtrim = function() {
    return this.replace(/([\s/n]*$)/g, "");
}

你可能感兴趣的:(function)