form表单中用name属性传值


    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和下拉列表获取值



转载于:https://my.oschina.net/chenxiaoxiao/blog/718511

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值