JavaScript判断前缀、后缀是否是空格的方法
本文实例讲述了JavaScript判断前缀、后缀是否是空格的方法。分享给大家供大家参考。具体如下:
//Js判断后缀
String.prototype.endsWith=function(suffix){
returnthis.indexOf(suffix,this.length-suffix.length)!==-1;
};
//Js判断前缀
if(typeofString.prototype.startsWith!='function'){
//seebelowforbetterimplementation!
String.prototype.startsWith=function(str){
returnthis.indexOf(str)==0;
};
}
//Js判空(含全部是空格)
String.prototype.IsNullEmptyOrSpace=function()
{
if(this==null)returntrue;
returnthis.replace(/s/g,'').length==0;
};
希望本文所述对大家的javascript程序设计有所帮助。