html - 如何使输入文本显示格式为十进制格式 0.00
问题描述
我正在使用一个<input type="text">
给员工的工作时间。我想将文本格式显示为0.00
并使其仅接受两位数字和两位十进制数字作为十进制格式。
<td>
<input type="text" asp-for="NormalHrs" class="col-sm-5" maxlength="5" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) ||event.charCode == 46 || event.charCode == 0 " />
</td>
解决方案
我们可以这样做这个js,
首先做一个事件(focusout/onclick你喜欢哪个)
输入类型应为“数字”
<input type="number" onfocusout="setTwoNumberDecimal(this)" step="0.01" value="0.00"/>
function setTwoNumberDecimal(el) {
el.value = parseFloat(el.value).toFixed(2);
};
推荐阅读
- python - Python firebase 存储模拟器
- python - 如何在 statsmodels 中向 OLS 公式添加自变量常量?
- mysql - 多对多关系中的多个 GROUP_BY 和 GROUP_CONCAT
- c - 如何在 C 程序中从文本文件中删除一个单词?
- django - 下一个身份验证 - OAUTH_GET_ACCESS_TOKEN_ERROR
- python - “FileNotFoundError: [Errno 2] No such file or directory:” 我该如何解决这个问题?
- python - 读取txt文件时如何在熊猫中左对齐
- javascript - POST From 无需重新加载页面 [Flask] - 其他方法无效
- flutter - Flutter 网页上的 Index.html
- r - 有了这些等式,如果我们知道一年内每个部门工作的初始人数,我们就可以估计下一年的人数