使用form裏面的button跳轉到其他頁面

在使用表單的時候,有時需要從一個頁面跳轉到多個不同的頁面。

比如:想要從1.jsp跳轉到2.jsp和3.jsp。


我們可以這樣寫程序:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>跳轉</title>
<script type="text/javascript">
	//把表單的action改爲2.jsp
	function Two() {
		document.form.action = "2.jsp";
		document.form.submit();
	}
	//把表單的action改爲3.jsp
	function Three() {
		document.form.action = "3.jsp";
		document.form.submit();
	}
</script>
</head>
<body>

<form action="" method="post" name="form">
<table width="300" border="1" align="center" bgcolor="#9AD3A4" bordercolor="red">
<tr><td align="center" colspan="2" >button跳轉</td></tr>
<tr>
<td><input type="button" value="跳轉到2.jsp" οnclick="Two()"      class="botton"/></td>
<td><input type="button" value="跳轉到3.jsp" οnclick="Three()"    class="botton"/></td>
</tr>
</table>
</form>
</body>
</html>
我們就可以從1.jsp跳轉到2.jsp或者是3.jsp從而實現一個頁面訪問多個頁面。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章