嗨,我在html type = number
中有两个文本框<input data-sign="BHD " type="number" class="widthinput input__field input__field--yoshiko validation-passed" value="" name="special_price" id="special_price">
<input data-sign="BHD " value="" type="number" class="required-entry validate-zero-or-greater input__field input__field--yoshiko validation-passed" name="price" id="price">
这是我的JS代码
if(parseFloat(jQuery('#special_price').val()) >= parseFloat(jQuery('#price').val())){
console.log(parseFloat(jQuery('#special_price').val()));
console.log(parseFloat(jQuery('#price').val()));
alert("You can't enter special price greater than price");
jQuery("html, body").animate({ scrollTop: 0 }, "slow");
e.preventDefault();
return false;
}
当我输入
之类的值时价格:160,Special_price:90
此JS条件正常工作,但是当我输入
之类的值时价格250.750,特价55.350
这种情况失败并给我带来了控制台的错误
An invalid form control with name='price' is not focusable.
An invalid form control with name='special_price' is not focusable.
我在镀铬浏览器上。
您的代码正在工作,请检查您的jQuery库。参考jsfiddle
或将novalidate
属性添加到表单中会有所帮助:
<form name="myform" novalidate>
update
号码类型具有step
值控制哪个数字有效(以及max
和min
),该数字默认为 1 。实现步进按钮也使用了此值(即按step
按增加增加)。
<input type="number" step="0.01">
只需将此价值更改为适当的。为了赚钱,可能会有两个小数:
(如果只能为正),我还将设置为min = 0)
如果您希望允许任何数量的小数位置,则可以使用step="any"
(尽管对于货币,我建议坚持0.01)。在Chrome&amp;使用any
时,firefox,步进按钮将增加/减小1,并在此处查看相关规格)
这是一个操场,显示各种步骤如何影响各种输入类型:
<form>
<input type=number step=1 /> Step 1 (default)<br />
<input type=number step=0.01 /> Step 0.01<br />
<input type=number step=any /> Step any<br />
<input type=range step=20 /> Step 20<br />
<input type=datetime-local step=60 /> Step 60 (default)<br />
<input type=datetime-local step=1 /> Step 1<br />
<input type=datetime-local step=any /> Step any<br />
<input type=datetime-local step=0.001 /> Step 0.001<br />
<input type=datetime-local step=3600 /> Step 3600 (1 hour)<br />
<input type=datetime-local step=86400 /> Step 86400 (1 day)<br />
<input type=datetime-local step=70 /> Step 70 (1 min, 10 sec)<br />
</form>
当我将其更改为 type =" text" 时,问题是 type =" number" ,我正在从js验证数字现在正常工作。