将的textboxfor设置为接受小数点后2位
set textboxfor to accept 2 decimal places
我有这两个textboxfor,我需要它们只允许输入小数点后2位。我假设jQuery或Javascript事件可以做到这一点。我只是不知道如何在Javascript中调用textboxfor。如有任何帮助,将不胜感激
@Html.TextBoxFor(m => Model.Categories[c].EstimateGroups[g].EstimateItems[i].PerUnitCost,
new { @disabled = "disabled", @onchange = "costUpdate(this);", @cstType = "perUnit",@id="perUnit"})
<span class="sideLabel">@Model.Categories[c].EstimateGroups[g].EstimateItems[i].PerUnitDescription</span>
if (Model.Categories[c].EstimateGroups[g].EstimateItems[i].Units != null
&& !Model.Categories[c].EstimateGroups[g].EstimateItems[i].IsBasedOnHomeSquareFootage)
{
@Html.TextBoxFor(m => Model.Categories[c].EstimateGroups[g].EstimateItems[i].Units,
new { @disabled = "disabled", @onchange = "costUpdate(this);", @cstType = "units" })
}
您可以使用RegularExpression属性。这将完成任务。
[RegularExpression(@"^'d+.'d{0,2}$",
ErrorMessage = "It cannot have more than one decimal point value")]
public double PerUnitCost {get;set;}
这里,在{0,2}
中,0和2表示小数点后的最小和最大数字。所以根据您的要求进行更改。
相关文章:
- 将数字四舍五入到小数点后两位
- 将数字四舍五入到小数点后两位,以设置货币格式
- AngularJS {{ val | number:1 }} 不四舍五入到小数点后 1 位
- 使用AngularJS将HTML文件中的数字限制为小数点后2位
- 如何在javascript中获取no的小数点后三位
- 用Javascript显示价格,小数点后两位
- 小数点后两位四舍五入-找不到正确的公式
- 将值提交到小数点后 2 位
- 如何将结果固定为小数点后 2 位
- 如何在输入上转换为小数点后 2 位
- 如何将小数向上舍入到小数点后 n 位
- 将 JavaScript 数字转换为小数点后两位
- 将结果限制在小数点后 2 位
- 更改为在小数点后添加 2 位数字
- Javascript 将数字舍入到小数点后 2 位
- 将数字舍入到小数点后两位,并删除任何其他小数点
- 防止用户在小数点前 2 位数字后输入更多数字
- 在谷歌图表中以小数点后两位显示数字
- 在 Javascript 中难以将 json 对象值四舍五入到小数点后两位
- 如果为float,则显示小数点2位;如果为int,则显示十进制0位