Home  >  Article  >  Web Front-end  >  Example sharing of JS judging input value

Example sharing of JS judging input value

小云云
小云云Original
2018-03-02 15:18:091584browse

How to determine the input value? This article mainly shares with you examples of JS judging input values, hoping to help everyone.

  1. 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(&#39;test&#39;);
function send(){
  if (zhi.value == &#39;&#39;){
     alert(&#39;input cannot be none&#39;);
  }else{alert(&#39;Successful&#39;);}
         }
  </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:

908e0106528dfe4086692d220848b00b

Related recommendations:

javascript code implements the fuzzy prompt function of the input input box

Input attributes in PHP

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn