javascript解决IE8一下浏览器不支持trim属性的兼容性问题

if(!String.prototype.trim){

  String.prototype.trim=function(){
    return this.replace(/^\s+|\s$/g,"");
  }  
   
}

例:var str="  Hello Javascript  ";

       str=str.trim();

      document.write(str);

猜你喜欢

转载自www.cnblogs.com/mchtig/p/9266674.html