读书人

javascript中trim(), startsWith(), e

发布时间: 2012-09-12 09:21:30 作者: rapoo

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)}

读书人网 >JavaScript

热点推荐