String.prototype.trim = function() {
//return this.replace(/[(^\s+)(\s+$)]/g,"");//會把字符串中間的空白符也去掉
//return this.replace(/^\s+|\s+$/g,""); //
return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
}
測試如下:
var str = "sdf sdfdsdfds ";
alert(str.trim(str));
1246

被折叠的 条评论
为什么被折叠?



