`
yanzhihong23
  • 浏览: 57745 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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

JS 
阅读更多

 

 

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)
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics