How to determine the input value? This article mainly shares with you examples of JS judging input values, hoping to help everyone.
Driven by button click events, the method document.getElementById() obtains the input(id) object, and then defines the function to determine whether the input value is a valid input.
<body> <input type="text" id="test" onclick="send();"/> <button onclick="send()">send</button> <script> var zhi = document.getElementById('test'); function send(){ if (zhi.value == ''){ alert('input cannot be none'); }else{alert('Successful');} } </script>
***Question: Assign value to zhi through document.getElementById.value(), and then judge the value. Could it be that the previously entered value has been saved in the memory, and regardless of whether there is a value in the text box, it is judged to have a value, and the Successful window pops up.
2. Determine after the cursor is out of focus through onblur
Verify when the user leaves the input field:
<input type="text" id="test" onblur="send">
Related recommendations:
javascript code implements the fuzzy prompt function of the input input box
Summary of various methods of jQuery operating input values _jquery
The above is the detailed content of Example sharing of JS judging input value. For more information, please follow other related articles on the PHP Chinese website!