js去空 去除空格

/**
 * 去除左侧空格
 */
function lTrim(str) {
    if (str) {
        return str.replace(/(^s*)/g,"");
    }
    return null
}

/**
 * 去除右侧空格
 */
function rTrim(str) {
    if (str) {
        return str.replace(/(s*$)/g,"");
    }
    return null
}

/**
 * 去除两侧空格
 */
function trim(str) {
    if (str) {
        return str.replace(/(^s*)|(s*$)/g, "");
    }
    return null
}
原文地址:https://www.cnblogs.com/jindao3691/p/14921980.html