form表单中用name属性传值

来源:互联网 发布:现货白银看盘软件 编辑:程序博客网 时间:2024/06/08 09:02
<%@ 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>
</head>
<%
String paramByRequest = request.getParameter("test");
String selectTest = request.getParameter("selectTest");
out.print("获取参数:"+paramByRequest);
out.print("获取参数:"+selectTest);
%>
<body>
<form action="">
<input name="test" value=""/>
<select name="selectTest">
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
</select>
<button type="submit" >提交</button>
</form>
</body>
</html>

当点击提交按钮的时候,form 表单提交本页面,通过name=“test” 的标签来传递其name=“test” 对应的value值;下拉列表中通过name=selectTest的传值。也可将action="" 跳转到另一个页面进行表单提交。


有点时候需要用Jquery传值

A.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>
</head>
<body>
<form action="">
<input name="test" value=""/>
<select name="selectTest">
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
</select>
<div id="iii">测试</div>
</form>
<script type="text/javascript" src="jquery-1.5.1.js"></script>
<script type="text/javascript">
$(function(){
$("#iii").click(function click1(){
var testBy = $("[name=test]").val(); 
var selectTest = $("[name=selectTest]").val(); 
var src="index9.jsp?";
src += "T1="+testBy+"&T2="+selectTest;
window.location.href = src;
});
});
</script>
</body>
</html>

点击事件跳转到的index9.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>Insert title here</title>
</head>
<body>
<%
String paramByRequest = request.getParameter("T1");
String selectTest = request.getParameter("T2");
out.print("获取参数1:"+paramByRequest);
out.print("获取参数2:"+selectTest);
%>
</body>
</html>

============以上是简单的input和下拉列表获取值



原创粉丝点击