JavaScript中带逗号的数字 [英] Numbers with commas in Javascript

查看:62
本文介绍了JavaScript中带逗号的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript函数,可以接受数字并对该数字执行数学运算.但是,我传入的数字可能会有逗号,并且由于我对Javascript的有限经验,我在使用该值时遇到了问题.似乎没有将其视为数字类型.

I have a javascript function that accepts a number and performs a mathematical operation on the number. However, the number I'm passing in could have a comma in it, and from my limited experience with Javascript I am having problems working with that value. It doesn't seem to treat that as a numeric type.

获取值1000的参数并将其转换为数字1000的最简单方法是什么?

What's the easiest way to take a parameter with a value of 1,000 and convert it to a numeric 1000?

推荐答案

您可以将文本框设置为具有 onblur()功能,以便当用户尝试离开文本框时,然后将其删除使用javascript 替换函数

You can set up your textbox to have an onblur() function so when the user attempts to leave the textbox, you then remove the commas from the value by using the javascript replace function

示例:

  function checkNumeric(objName)
  {
    var lstLetters = objName;

    var lstReplace = lstLetters.replace(/\,/g,'');
  }  

在此处带有输入标签:

<input type="text" onblur="checkNumeric(this);" name="nocomma" size="10" maxlength="10"/>

这篇关于JavaScript中带逗号的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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