validity.valid 是如何工作的? [英] How does validity.valid works?

查看:32
本文介绍了validity.valid 是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将输入数字 (html) 设置为仅正数,但我找到了这个很好的解决方案:

I was trying to set an input number (html) to only positive numbers and I found this fine solution:

    <input type="number" name="test_name" min="0" oninput="validity.valid|| 
    (value='');">

谁能告诉我 oninput="validity.valid||(value=''); 是如何工作的?它如何将输入限制为仅正数.

Can anyone tell me how does oninput="validity.valid||(value=''); works? How does it restrict the input to only positive numbers.

谢谢!

推荐答案

min="0" 只接受大于零的数字.因此,当用户输入一个值 (oninput) 时,它要么是有效的 (validity.valid),要么是 (||) 值被替换通过空字符串 (value='').

min="0" only accept numbers greater than zero. So when the user enters a value (oninput), either it is valid (validity.valid) or (||) the value is replaced by an empty string (value='').

validity.valid 因为 min="0" 是假的,我们可以看到 rangeUnderflow属性下的文档:

validity.valid is falsy because of min="0" as we can see in the doc under the rangeUnderflow property:

如果该值小于 min 属性指定的最小值".

"if the value is less than the minimum specified by the min attribute".

这篇关于validity.valid 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆