0
我有一个jsp页面具有以下的值:JSP第二下拉取决于选择的第一
<select name="classTitle" id="classTitle">
<option value="-1" name="title">Select class</option>
<%
try{
String qr="select * from class";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/lab3","root","");
Statement stm=conn.createStatement();
ResultSet rs=stm.executeQuery(qr);
while(rs.next()){
%>
<option id="selectedClass" value="<%=rs.getString("classTitle")%>"><%=rs.getString("classTitle")%></option>
<%
}//end while
}//end try
catch(Exception ex){
ex.printStackTrace();
out.println("Error "+ex.getMessage());
}
%>
</select>
我要添加到相同的形式的另一字段,它会保持相应的类尺寸(存储在表类)为选择的特定类。然后这些值将被传递给Servlet。
到目前为止,我已经尝试
<script>
$('#classTitle').on('change', function(e){
$("#results").html("You selected: " + selected);
});
</script>
和
<div id="results"></div>
测试 - 不工作(可能是因为原来的形式本身就是一个弹出窗口)。
你在这段代码期待? 'selected'在这里没有定义。所以这会很复杂。你有没有搜索“jquery选择onchange”选项?你应该找到一些答案。 – AxelH
[jQuery获取select onChange的值的可能重复](http://stackoverflow.com/questions/11179406/jquery-get-value-of-select-onchange) – AxelH