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

Example sharing of JS judging input value

小云云
Release: 2018-03-02 15:18:09
Original
1663 people have browsed it

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>
Copy after login

***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">
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template