-1
<%@ 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 葡萄中的任何一个并在按钮单击或更改选择时提交它然后值传递但部分值设置为选择选项时我必须设置它我在提交之前设置例如如果我们选择橙色然后在提交之后喊设置值到下拉并且值传递也请帮助我能够传递值但无法在提交后在下拉中设置值。

4

1 回答 1

0

按文本选择下拉菜单

工作演示http://jsfiddle.net/cse_tushar/L6p2u/

js

$(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/

js

$(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;
        }
    }
});
于 2013-07-18T07:49:23.073 回答