The form cannot be left empty to submit a reminder:
When working as an administrator system, there are A problem with the backend is that the data submitted in the front-end form cannot have blank fields. The solution at that time was to use native js to operate the DOM to perform judgment and pop-up operations.
Later, when browsing the community, I found that , the form has an event onSubmit. This event can be understood as being triggered just before the form is submitted. At this time, we can pass an event to this event. Callback function, and in the callback function, perform the verification code for whether there is a blank form, and the reminder code.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script src = "checkNull.js"></script> </head> <body> //表单在进行提交的前一刻会调用onsubmit事件,这个事件会接受checkInput这个函数的返回值。 <form action="" onsubmit = "return checkInput(this)"> <input type="text" placeholder="请输入用户名"> <input type="text" placeholder="请输入密码"> <input type="submit"> </form> </body> </html> <script> function checkInput(form) { for (let i = 0; i < form.length; i++) { alert("进来了"); if (form.elements[i].value == "") { alert("请您输入" + form.elements[i].placeholder); form.elements.onfocus(); //这里返回一个Boolean值,从而确定表单是否能够提交 return false; } } } </script>
Recommended: layui framework tutorial
The above is the detailed content of Layui determines whether the form is empty. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Layui's flow module for infinite scrolling, covering setup, best practices, performance optimization, and customization for enhanced user experience.

The article details how to use Layui's element module to create and customize UI elements like tabs, accordions, and progress bars, highlighting HTML structures, initialization, and common pitfalls to avoid.Character count: 159

The article discusses customizing Layui's carousel module, focusing on CSS and JavaScript modifications for appearance and behavior, including transition effects, autoplay settings, and adding custom navigation controls.

The article guides on using Layui's carousel module for image sliders, detailing steps for setup, customization options, implementing autoplay and navigation, and performance optimization strategies.

The article discusses configuring Layui's upload module to restrict file types and sizes using accept, exts, and size properties, and customizing error messages for violations.

The article explains how to use Layui's layer module to create modal windows and dialog boxes, detailing setup, types, customization, and common pitfalls to avoid.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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