<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!--MD5工具类--> <script src="https://cdn.bootcdn.net/ajax/libs/blueimp-md5/2.16.0/js/md5.min.js"></script> </head> <body> <!-- 表单绑定提交事件 onsubmit=绑定一个提交检测的函数,true,false 将这个结果返回给表单,使用onsubmit接收 --> <form action="https://www.baidu.com/" method="post" onclick="return aaa()"> <p> <span>用户名:</span> <input type="text" id="username" name="username"> </p> <p> <span>密码:</span> <input type="password" id="input-password"> </p> <input type="hidden" id="md5-password" name="password"> <!--绑定事件onclick被点击--> <button type="submit">提交</button> </form> <script> function aaa() { alert(1); var uname=document.getElementById('username'); var pwd=document.getElementById('input-password'); var md5pwd=document.getElementById('md5-password'); // pwd.value=md5(pwd.value); md5pwd.value=md5(pwd.value); //可以检验判断表单内容,true就是通过提交,false阻止提交 return false; } </script> </body> </html>