点击按钮触发事件

拥有回忆 提交于 2019-12-11 03:55:53

在使用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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!