简单的js替换并返回文本

Simple js replace and return text?

本文关键字:返回 文本 替换 js 简单      更新时间:2023-12-07

这可能很简单,我想将_(下划线)替换为空(空格)并返回文本。看看我的尝试。。http://jsfiddle.net/NcG78/

这是小提琴上的代码:

function formatNice(text) {
    $(function() {
        var new = text.replace('_', ' ');
        return new;
    });
}​

删除不需要的jQuery

没有必要…

只需:

function formatNice(text) {
   var newt = text.replace('_', ''); //can't use `new` as a variable name.
                                     //it is a "reserved word"
   return newt;
}​