English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
提交事件会在用户点击提交按钮( <input type="submit"/> 元素在提交表单时触发。
当提交表单时运行onsubmit:
<!DOCTYPE html> <html> <head> <title>HTML onsubmit 事件属性的使用(基础教程网 oldtoolbag.com)</>title> </>head> <body> <p>提交表单后,将弹出一个提示框.</>p> <form action="demo-form.php" onsubmit="myFunction()"> Enter Name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> <script> function myFunction() { alert("Form submitted"); } </script> </body> </html>Test and see ‹/›
IEFirefoxOperaChromeSafari
All major browsers support the onsubmit event attribute
The onsubmit attribute is triggered when a form is submitted.
The onsubmit attribute is only applicable to <form> elements.
No difference.
<form onsubmit="script">
Value | Description |
---|---|
script | Specifies the script to be executed when the onsubmit event is triggered. |