运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <p>Use the addEventListener() method to attach a "submit" event to a form element.</p> <p>When you submit the form, a function is triggered which alerts some text.</p> <form id="myForm" action="/action_page.php"> Enter name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> <script> document.getElementById("myForm").addEventListener("submit", myFunction); function myFunction() { alert("The form was submitted"); } </script> </body> </html>