E8浏览器对JavaScript中的endswith,start

2019-07-26  本文已影响0人  wetCoder

wetCoder

一个湿身的程序员,在编程的路上,一路爬行~

IE8浏览器对JavaScript中的endswith,startWith,trim,indexOf等方法(不支持)不兼容等问题处理

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

然后在使用这个endWith方法。

if("0" == limitAreaLevel && id.toString().length != 2 ){
  alert("业务逻辑视自己代码情况而定");
 }

这样的话就避免了IE8 对endswith 不支持的问题!

wetCoder

一个湿身的程序员,在编程的路上,一路爬行~

上一篇 下一篇

猜你喜欢

热点阅读