javascript - 带有初始值的错误十进制数值(Inputmask JQuery)
问题描述
我的初始化值有问题。初始值2042.09
应该是2.042,09
,但它给出204.209,00
$(".target").inputmask('numeric', {
radixPoint:",",
groupSeparator: ".",
allowMinus: false,
unmaskAsNumber: true,
digits: 2,
removeMaskOnSubmit: true,
autoUnmask: true,
digitsOptional: false,
})
- JSFiddle:https ://jsfiddle.net/0mfjg5t6/7/
- 操作系统:Windows 10
- 浏览器:铬
- 输入掩码版本:5.0.5
解决方案
该文档说明了有关设置初始值的以下内容:
//html
<input name="npt" value="123456,789"/>
//js
Inputmask("decimal", {
radixPoint: ',',
inputtype: "text"
}).mask("input");
$("input").val("123456,789");
$("input").val(123456.789); //this doesn't work because jQuery converts the number to a string before passing it along to the Inputmask.
document.getElementsByName("npt")[0].value = "123456,789";
document.getElementsByName("npt")[0].value = 123456.789; //type number
即在 HTML 中或通过 jQuery 声明初始值时,您需要尊重语法.val()
。
推荐阅读
- azure - Azure 数据工厂监视器显示仪表板没有数据
- sql - 在 SQL Server 中查找丢失的外键/主键
- terraform - 在 Terraform 上需要帮助来为基于 Java 的应用程序创建应用程序服务
- docker - HTTPS 上的 SiteSpeed.IO 指标 InfluxDB
- apache-flink - 计时器(堆与 RocksDB)
- javascript - 如果另一个数组包含对象,如何减少对象数组?
- wso2 - 登录 wso2-is 没有租户域
- c++ - 在变量前面添加 : 会给出错误的结果
- clojure - 不同命名空间中的 Clojurescript defprotocol 和 defrecord
- mips - 我在 MIPS 中写了一个循环,但由于某种原因它一直在无限运行?