如何防止用户在kendo数字文本框中输入超过4 uinits的精度 [英] How can I prevent a user from typing more then 4 uinits of precision in a kendo numeric textbox
本文介绍了如何防止用户在kendo数字文本框中输入超过4 uinits的精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要求用户输入4个精度单位的小数。但只显示3.有没有办法让kendo-ui数字文本框阻止超过4个单位的精度?
I have a requirement to allow a user to type a decimal with 4 units of precision. But only display 3. Is there a way to have the kendo-ui numerictextbox prevent more then 4 units of precision?
$element.kendoNumericTextBox({
spinners: false,
culture: "en-US",
decimals: 4,
step: 0.01,
format: "n3"
});
推荐答案
我认为没有配置选项,但你可以这样做:
I don't think there's a configuration option for that, but you can do something like this:
var numeric = $("#num").kendoNumericTextBox({
spinners: false,
culture: "en-US",
decimals: 4,
step: 0.01,
format: "n3"
}).data("kendoNumericTextBox");
$(numeric.element).on("input", function (e) {
var val = numeric.element.val();
var parts;
if (val.indexOf(".") !== -1) {
parts = val.split(".");
if (parts[1].length > 4) {
numeric.element.val(val.substr(0, val.length - 1));
}
}
});
(演示)
这篇关于如何防止用户在kendo数字文本框中输入超过4 uinits的精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文