写一个function,清除字符串前后的空格。(兼容所有浏览器)

代码:

function trim(str) {
    if (str && typeof str === "string") {
        return str.replace(/(^\s*)|(\s*)$/g,""); //去除前后空白符
    }
}

.

posted @ 2019-04-09 21:30  每天都要进步一点点  阅读(1996)  评论(0编辑  收藏  举报