原生js实现trim方法,过滤字符串首位空白

 

 

function trim(str){

    str = str.replace(/^\s+/,"");

    str = str.replace(/\s+$/,"");

    return str;

}

 

posted @ 2017-07-09 22:00  YiRan2011  阅读(618)  评论(0编辑  收藏  举报