js函数扩展
扩展去除字符串后面的字符或者空格
//去掉字符串两端的字符
String.prototype.trim = function() {
var charlist = arguments[0] || ''; if(charlist == '') return this.replace(/(^\s*)|(\s*$)/g, "");
else return this.replace(eval('/(^\\'+charlist+'*)|(\\'+charlist+'*$)/g'), "");
}
/*** 默认去掉字符串左边所有空白
*/
String.prototype.ltrim = function(charlist) {
var charlist = charlist || '';
if(charlist == ''){
return this.replace(/(^\s*)/g, "");
}else{
var reg = '/(^\\'+charlist+'*)/g';
return this.replace(eval(reg), "");
}
}
/*** 默认去掉字符串右边所有空白*/
String.prototype.rtrim = function(charlist) {
var charlist = charlist || '';
if(charlist == ''){
return this.replace(/(\s*$)/g, "");
}else{
var reg = '/(\\'+charlist+'*$)/g';
return this.replace(eval(reg), "");
}
补充:web前端 , JavaScript ,