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

One sentence JavaScript form validation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:48:42930browse

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
.
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