源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <p>当你提交这个表单时,会触发一个函数,会显示一些信息</p> <form action="demo_form.php" onsubmit="myFunction()"> 输入姓名: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> <script> function myFunction() { alert("表单被提交了"); } </script> </body> </html>
运行结果