您的位置:首页 > 博客中心 > 前端开发 >

js去空 去除空格

时间:2022-04-11 14:43

/**
 * 去除左侧空格
 */
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
}

 

本类排行

今日推荐

热门手游