HTML基础小结
一、HTML_input数值输入框加验证
type类型为“number”
设置最大数300 最小数100
required表示必填项
<input id="id1" type="number" min="100" max="300" required>
验证js代码如下
<script> function myFunction(){ var inpObj=document.getElementById("id1"); if(inpObj.checkValidity() == false){ document.getElementById("demo").innerHTML = inpObj.validationMessage; } else{ document.getElementById("demo").innerHTML = "输入正确"; } } </script>