运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗色/亮色
转到空间
<!DOCTYPE html> <html> <body> <p>Use the HTML DOM to assign an "onsubmit" 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").onsubmit = function() {myFunction()}; function myFunction() { alert("The form was submitted"); } </script> </body> </html>