onsubmit 表單提交事件
阿新 • • 發佈:2022-03-17
靜態登錄檔單提交事件
如果發現提交不合法,可以通過onsubmit="return false"阻止表單提交
<head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> alert("使用") var onsubmitfun = function (){ alert("靜態登錄檔單提交") } </script> </head> <body> <form method="get" action="https://localhost:8080"> <input type="submit" value="靜態提交" onsubmit="onsubmitfun()"> </form>
動態提交事件
<head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> window.onload = function () { var onsubmit = document.getElementById("form01") onsubmit.onsubmit = function (){ alert("動態註冊不合法") return false } } </script> </head> <body> <form action="https://localhost:8080" id="form01" method="get"> <input type="submit" value="動態提交"/> </form> </body>