使用Javascript删除逗号以获取值 [英] Removing comma for value with Javascript

查看:65
本文介绍了使用Javascript删除逗号以获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您查看我的问题,我找不到用javascript删除逗号的方法。所以我在使用java脚本从页面中删除逗号时遇到问题,我猜想添加逗号输出很好,但是为了删除逗号值,该功能对我来说不起作用。

thanks for looking my questions, I can't find the way to remove the comma with javascript. So I have problem at removing comma from page with java-script, Adding Comma for output is fine i guess, but for removing comma for value, the function is not working for me.

源代码为: http://jsfiddle.net/Q5CwM/2/

请让我知道,再次感谢。

Please let me know, thanks again.

推荐答案

我不知道您的代码总体上尝试做什么,但您可以修复此函数以删除逗号:

I have no idea what your code is trying to do overall, but you can fix this function that removes commas:

function checkNumeric(objName) {
    var lstLetters = objName;
    var lstReplace = lstLetters.replace(/\,/g,'');
}

将其更改为:

function removeCommas(str) {
    return(str.replace(/,/g,''));
}

您没有从函数返回更改后的字符串而我更改了名称函数和参数表示它的作用。

You weren't returning the changed string from the function and I changed the name of the function and parameters to represent what it does.

str.replace 返回更改后的字符串。它不会更改您开始使用的字符串,因此为了对替换结果执行某些操作,您必须从函数返回该函数或将其分配给其他字符串。就像你拥有它一样,替换后的字符串没有发生任何事情,所以函数什么也没做。

str.replace returns the changed string. It does not change the string you started with so in order to do something with the result of the replacement, you have to either return that from the function or assign it to some other string. As you had it, nothing was happening with the replaced string so the function did nothing.

这篇关于使用Javascript删除逗号以获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆