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

posted @ 2018-07-05 09:47  mchtig  阅读(136)  评论(0编辑  收藏  举报