admin管理员组

文章数量:1277271

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

The source code is : /

Please let me know, thanks again.

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

The source code is : http://jsfiddle/Q5CwM/2/

Please let me know, thanks again.

Share Improve this question asked Oct 20, 2011 at 22:08 XML guyXML guy 3994 gold badges6 silver badges16 bronze badges 3
  • 2 What is your question? Where are you trying to remove the ma from? Looking at your jsFiddle and there's no ma on your number output. – Jonathon Bolster Commented Oct 20, 2011 at 22:12
  • checkNumeric() function is removing the ma, Comma() function is adding the ma. If you see this -> jsfiddle/Q5CwM/1/ that page doesn't have ma at all. But I want to add ma for display. So I add the ma function and use at line 69 for adding ma. And I tried to use removing ma at line 66. When i use that removing ma function, the page is having error of NaN. – XML guy Commented Oct 20, 2011 at 22:15
  • checkNumeric was removing the mas and then doing nothing with the result, thus nothing was changing. See my answer below for how to fix it. – jfriend00 Commented Oct 20, 2011 at 22:19
Add a ment  | 

1 Answer 1

Reset to default 6

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

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

by changing it to this:

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 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.

本文标签: Removing comma for value with JavascriptStack Overflow