本文实例讲述了javascript判断前缀、后缀是否是空格的方法。分享给大家供大家参考。具体如下:
// js 判断后缀 string.prototype.endswith = function(suffix) { return this.indexof(suffix,this.length - suffix.length)!==-1; }; // js 判断前缀if (typeof string.prototype.startswith != 'function') { // see below for better implementation! string.prototype.startswith = function (str){ return this.indexof(str) == 0; };} // js 判空(含全部是空格)string.prototype.isnullemptyorspace = function() { if (this== null) return true; return this.replace(/s/g, '').length == 0; };
希望本文所述对大家的javascript程序设计有所帮助。