在实际开发中,我们要多次输入密码进行测试,为了避免重复操作我们可以给表单设置默认值,自动提交登录,代码如下:
html:
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>登录</title> </head> <body> <h1>请登录</h1> <hr> <form id="login_form" action="/plat/userlogon" method="post"> 用户: <input type="text" id="userAccount" name="userAccount" value="cpy"/><br/><br/><br/> 密码:<input type="password" id="password" name="password" value="lffabc123"/><br/><br/><br/> 验证码:<input type="text" id="code" name="code" th:attr="value=${yzm}"/> <h1 th:text="${yzm}"></h1><br/><br/><br/> <input type="submit" value="提交"/> <input type="reset" value="重置"/> </form> <script> /*自动提交*/ let elementById = document.getElementById(`login_form`); elementById.submit(); </script> </body> </html>
注:使用了Springboot+thymleaf模板引擎