在我的脚本中,除了空输入的输出之外,一切正常。如何查找输入是否为空?
<input id="id1" type="number" max="100" min="40">
<button onclick="count()">OK</button>
<p id="test"></p>
<script>
var inpObj = document.getElementById('id1');
function count() {
if(inpObj.checkValidity() == false || inpObj.length === 0) {
document.getElementById('test').innerHTML = inpObj.validationMessage;
} else {
document.getElementById('test').innerHTML = "Input OK";
}
}
</script>
我不知道为什么这不起作用。
谢谢。
的价值是什么'inpObj.checkValidity'和'in pObj.validationMessage'?你是什么意思,它不工作?浏览器控制台中是否有错误? – gurvinder372
我正在学习本教程,它是javascript验证api部分:http://www.w3schools.com/js/js_validation_api.asp – super11