我怎么能限制只接受两位小数点,或者我怎么能格式化只有两位小数点。我尝试了模型RegularExpression(@"^\d+.\d{0,2}$“),我尝试了@step 01和tabindex 7,仍然不起作用,我们可以给出两个以上的小数。以下是代码
@Html.TextBoxFor(m => m.attendanceLogList[i].NormalHrs, new
{
@class = "form-control input-sm emphrs",
@style = columnstyle,
@Value = Model.attendanceLogList[i].NormalHrs,
@type = "number",
@step = ".01",
onchange = "CalculateTotal(this);"
})发布于 2021-05-30 04:29:32
假设onchange事件CalculateTotal(this);是一个javascript函数。我的意思是,将下面的javascript应用到你的Razor代码片段中,以同样的方式,应该是有效的,仅供参考。
function fixDecimal(e) {
return e.value = e.value.toString().match(/^\d+(?:\.\d{0,2})?/);
}<input type="number" step="0.01" onkeyup="fixDecimal(this)" />
https://stackoverflow.com/questions/67685567
复制相似问题