<%@ page language="java" contenttype="text/html; charset=ISO-8859-1" pageencoding="ISO-8859-1" %>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="index.jsp" name="productForm">
<select name="colour" onchange="document.productForm.submit();">
<option value="dropdown">Pls select one
<option value="apple">Apple
<option value="oragne">Orange
<option value="grapes">Grapes
</select>
<input type="hidden" name="dropdown" id="dropdown">
<input type="submit" value="click" name="dropdown" id="dropdown">
<form>
<%
String colour = request.getParameter("colour");
out.println(colour);
%>
</body>
</html>
请检查我的代码ii当我选择任何一个苹果或橙色pr葡萄时下拉并按下按钮点击或更改选择提交然后值传递但是当我必须设置它时,部分值设置为选择选项它是我设置之前提交之前如果我们选择橙色然后提交后喊出设定值下降和值传递也请帮助我能够传递值但无法在提交后下拉设置值。
答案 0 :(得分:0)
按文字选择下拉列表
工作演示http://jsfiddle.net/cse_tushar/L6p2u/
$(document).ready(function () {
var textToFind = 'Orange';
var dd = document.getElementById('colour');
for (var i = 0; i < dd.options.length; i++) {
if (dd.options[i].text === textToFind) {
dd.selectedIndex = i;
break;
}
}
});
按值选择下拉列表
工作演示http://jsfiddle.net/cse_tushar/L6p2u/1/
$(document).ready(function () {
var valueToFind = 'oragne';
var dd = document.getElementById('colour');
for (var i = 0; i < dd.options.length; i++) {
if (dd.options[i].value === valueToFind) {
dd.selectedIndex = i;
break;
}
}
});