发表于: sitebuild | 作者: | 日期: 2009/6/23 03:06

方法一:
String.prototype.trim= function()
{
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, “”);
}

方法二:
function trim(str)
{
for(var i = 0 ; i0 && str.charAt(j-1)==” ” ; j–) ;
if(i>j) return “”;
return str.substring(i,j);
}

方法三:

//去左空格;
function ltrim(s){
return s.replace( /^\s*/, “”);
}

//去右空格;
function rtrim(s){
return s.replace( /\s*$/, “”);
}

//去左右空格;
function trim(s){
return rtrim(ltrim(s));
}

: https://blog.darkmi.com/2009/06/23/875.html

本文相关评论 - 1条评论都没有呢
Post a comment now » 本文目前不可评论

No comments yet.

Sorry, the comment form is closed at this time.