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中的模版引擎

原文地址:https://www.cnblogs.com/SeaWxx/p/11193347.html