首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-09-12 
javascript中trim(), startsWith(), endsWith() 函数的实现??String.prototype.trim function(){// 用正

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

热点排行