Home > Web Front-end > JS Tutorial > One sentence JavaScript form validation code_javascript skills

One sentence JavaScript form validation code_javascript skills

WBOY
Release: 2016-05-16 18:48:42
Original
976 people have browsed it

There are various writing methods for client-side JavaScript validation of forms. Log in to write a function for the form's onsubmit event or submit button. For small forms (forms with only one or two form fields), there is no need to write a verification function in JavaScript. You only need to add:

Copy code The code is as follows:
onsubmit="return domainname.value=="?(alert('Please enter the search content'),false):true ;"

With only one sentence, it realizes the function of submitting when the verification is successful and giving a prompt when it fails. The domainname is the name of the form field to be verified. Of course, when there are many form fields, It is not suitable to write like this when the verification process is complicated
.
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