


Examples to explain js method to verify whether form items are empty_javascript skills
May 16, 2016 pm 03:20 PMForm verification is essential for almost every website that requires registration or login. Some verifications are very complicated and can be said to be various requirements for you. However, this chapter only introduces the simplest form. The verification method is to determine whether it is empty. Some websites with lower requirements have already met this need.
The code is as follows:
<html> <head> <meta charset="gb2312"> <title>js简单表单验证</title> <script type="text/javascript"> window.onload=function() { var bt=document.getElementById("bt"); bt.onclick=function() { if(document.myform.name.value=="") { alert("用户名不能为空!"); document.myform.name.focus(); return false; } else if(document.myform.pw.value=="") { alert("密码不能为空!"); document.myform.pw.focus(); return false; } } } </script> </head> <body> <form action="index.php" method="get" name="myform"> <ul> <li>姓名:<input type="text" name="name" id="name" /></li> <li>密码:<input type="text" name="pw" id="age" /></li> <li><input type="submit" id="bt"/></li> </ul> </form> </body> </html>
The above is the detailed content of this article, I hope it will be helpful to everyone’s study.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed method to unblock using WeChat friend-assisted verification

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

Recommended: Excellent JS open source face detection and recognition project

New features in PHP 8: Added verification and signing

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS

How to solve the problem of steam login stuck in mobile token verification?
