在使用button时,如何点击按钮触发事件?
方法一:使用from表单中的action(仅有一个button时)
form action=“你需要跳转的页面”
button type=“设定类型”
eg:
<form action="check.jsp" method="get">
用户名<input type="text" name="username" />
<br>
密码<input type="password" name="psd" />
<br><br>
<button type="submit">登录</button>
</form>
方法二:设置onclick点击事件(多个button时)
form name=“起个名字”
input type=“button” οnclick=“document.刚起的名字.action=‘需要跳转的页面’;document.form1.submit()”
eg:
<form name="form1" method="get">
用户名:<input type="text" name="username" />
密码:<input type="password" name="psd" />
<input type="button" value="登录" onclick="document.form1.action='check.jsp';document.form1.submit()">
<input type="button" value="注册" onclick="document.form1.action='register.jsp';document.form1.submit()">
</form>
来源:CSDN
作者:G小吉
链接:https://blog.csdn.net/weixin_44302370/article/details/103479623