From 1ac8bba06812faf6af2259d8a890988a236dafa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:09:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20input=20=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E7=9A=84=E7=B2=BE=E5=BA=A6=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/form.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/form.js b/src/modules/form.js index 228dc1d6..0d6a713d 100644 --- a/src/modules/form.js +++ b/src/modules/form.js @@ -277,10 +277,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){ value: ['up', 'down'], split: true, className: 'layui-input-number', - disabled: disabled, // 跟随输入框禁用状态 + disabled: othis.is('[disabled]'), // 跟随输入框禁用状态 click: function(elem){ var index = $(this).index(); var value = elem.val(); + var rawValue = value; var step = Number(elem.attr('step')) || 1; // 加减的数字间隔 var min = Number(elem.attr('min')); var max = Number(elem.attr('max')); @@ -294,11 +295,15 @@ layui.define(['lay', 'layer', 'util'], function(exports){ if(value < min) value = min; if(value > max) value = max; - // 小数点后保留位数 - var fixed = function(step){ - var decimals = (step.match(/\.(\d+$)/) || [])[1] || ''; + // 获取小数点后位数 + var decimals = function(step){ + var decimals = (step.toString().match(/\.(\d+$)/) || [])[1] || ''; return decimals.length; - }(step.toString()); + }; + + // 位数比较 + var fixed = Math.max(decimals(step), decimals(rawValue)); + if(fixed) value = value.toFixed(fixed); elem.val(value);