我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
How can I use commas in number inserts so it doesn't break my input fields
我创建了一个计算表单,并用它进行了一些a/B测试,我注意到在一个领域中,许多要求"总捐赠者"的人会尝试使用"10,000"
而不是10000
。
我有没有办法让逗号可以放进去,但在JS中被忽略和未读?因此,它向用户显示10,000
,但我的脚本仍然将其读取为10000
。它必须在多个领域进行,有全球解决方案吗?
我对JS的了解还不够,甚至不知道如何开始攻击这个问题。我可以想象,它必须是某种类型的代码,计算字符串值,然后在里面弹出逗号,这样它就可以作为数字返回。
举个例子,我使用的字段也会根据输入的数字在总分中添加加分。由于计算表将被各种规模的机构使用,我们需要添加它来平衡它,这样拥有更多捐赠者的大公司就可以获得更多的分数,因为小公司的总分既不会受到惩罚。
小公司总分:400
适用奖金的公司的总分:420
奖金总额:
• val < 10001 = + 0
• val >= 10001 and < 25001 = + 10
• val >= 25001 and < 50000 = + 15
• val >= 50000 = + 2
我的输入如下(为了可读性而拆分):
<fieldset class="webform-component-fieldset form-wrapper" id="webform-component-constituent-base">
<legend><span class="fieldset-legend">Constituent Base</span></legend>
<div class="fieldset-wrapper"><div class="form-item webform-component webform-component-textfield" id="webform-component-constituent-base--total-constituents">
<label for="edit-submitted-constituent-base-total-constituents">Total Number of constituents in your database </label>
<input type="text" id="edit-submitted-constituent-base-total-constituents" name="submitted[constituent_base][total_constituents]" value="" size="60" maxlength="128" class="form-text" />
</div>
</div></fieldset>
我对此字段的计算
var donorTotal = jQuery("#edit-submitted-constituent-base-total-constituents").val();
if(donorTotal)
{
donorTotal = parseFloat(donorTotal);
}
else
{
donorTotal = 0;
}
grade += getBonusDonorPoints(donorTotal);
// End total # of donors
积分功能:
function getBonusDonorPoints(val)
{
if(val < 10001)
{
return 0;
}
else if(val >= 10001 && val < 25001)
{
return 10;
}
else if(val >= 25001 && val < 50000)
{
return 15;
}
else if(val >= 50000)
{
return 20;
}
}
谢谢你们能给我的任何帮助,让我指向并回答!
因此,请替换逗号,并确保使用的是数字而不是字符串。
Number(jQuery("#edit-submitted-constituent-base-total-constituents").val().replace(/,/g,""));
我会通过删除任何不是数字的东西来解决这个问题。这对诸如SSN、电话号码、邮政编码之类的字段非常有效,并且有利于这些字段的国际化。
function justTheNumbers(s) {
return s.replace(/'D/g, '');
}
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 而循环只设置php中输入字段中的第一个值
- 在输入字段中将最小金额设置为
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 如何在HTML输入字段中添加不可删除的后缀
- 互斥单选按钮和相应的输入字段
- 在IE9中的输入字段中输入焦点最近按钮
- 选中单选框时将属性添加到输入字段
- 当设置addFromAutocompleteOnly时,剩余文本将保留在输入字段中
- 我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
- 在输入字段上有两个函数调用,一个在Blur上,一个不在Angular中
- 输入字段将't获取更新的值
- 如何选择多个输入字段并删除所需的属性
- 输入字段,只接受0到12之间的数字
- 单击鼠标,用MySQL数据填充html表单输入字段
- 使用jquery将输入字段转换为文本
- Model中的Typeahead返回空值以形成输入字段
- 如何从查询字符串中的输入字段发回文本
- 如何验证日期、月份和日期的3个独立输入字段;年使用jquery或javascript
- 将值传递给jquery创建的输入字段