日期:2014-05-16  浏览次数:20418 次

javascript中trim(), startsWith(), endsWith() 函数的实现

?

?

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

?

String.prototype.startsWith = function(str){
	return (this.match("^"+str)==str)
}
?

?

?

String.prototype.endsWith = function(str){
	return (this.match(str+"$")==str)
}