js 去除收尾指定字符

 

 

// 去除收尾指定字符
String.prototype.trim = function (char, type) {
if (char) {
if (type == 'left') {
return this.replace(new RegExp('^\\'+char+'+', 'g'), '');
} else if (type == 'right') {
return this.replace(new RegExp('\\'+char+'+$', 'g'), '');
}
return this.replace(new RegExp('^\\'+char+'+|\\'+char+'+$', 'g'), '');
}
return this.replace(/^\s+|\s+$/g, '');
};

使用的layui中的模版引擎

 

 

posted @ 2019-07-16 10:36  Sea_wxx  阅读(553)  评论(0编辑  收藏  举报