在我的腳本中,除了空輸入的輸出之外,一切正常。如何查找輸入是否爲空?
<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