js 去字符串两边空格

 

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, "");
}

 

posted @ 2022-01-04 18:18  三瑞  阅读(66)  评论(0编辑  收藏  举报