<script type="text/javascript">
String.prototype.endWith=function(s){
if(s==null||s==""||this.length==0||s.length>this.length)
return false;
if(this.substring(this.length-s.length)==s)
return true;
else
return false;
return true;
}
String.prototype.endWith=function(s){
if(s==null||s==""||this.length==0||s.length>this.length)
return false;
if(this.substring(this.length-s.length)==s)
return true;
else
return false;
return true;
}
String.prototype.startWith=function(s){
if(s==null||s==""||this.length==0||s.length>this.length)
return false;
if(this.substr(0,s.length)==s)
return true;
else
return false;
return true;
}
if(s==null||s==""||this.length==0||s.length>this.length)
return false;
if(this.substr(0,s.length)==s)
return true;
else
return false;
return true;
}
String.prototype.trim= function(){
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
}
</script>
本文介绍了一种在JavaScript中对字符串方法进行封装的技术实现,包括endWith、startWith和trim等方法,这些方法能够帮助开发者更方便地处理字符串,提高开发效率。
1046

被折叠的 条评论
为什么被折叠?



