<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>form form submission</title> </head> <body> <form action="JS09.html" method="post" id="f"> <input type="text" id="a"> <input type="submit" value="提交" /> </form> </body> <script> var f = document.getElementById('f'); //get the input box var a = document.getElementById('a'); //Event listener for submit form f.onsubmit = function (){ //Check if there is content if(a.value==''){ alert('The content is empty, please fill in the user name'); // prevent form submission return false; } else { alert('Submission successful') // the form can be submitted return true; } } </script> </html>
Write form submission and judgment in JS
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325381163&siteId=291194637
Recommended
Ranking