jQuery 创建动态下拉列表
我目前正在使用jsp,我想创建一个动态下拉列表。当页面首次加载时,我有这个下拉列表:
<select name="target" id="target">
<option value="">--Select an option--</option>
<option value="add">Add a client with a program</option>
<option value="exit">Mark a client as exit client</option>
<option value="refuse">Refuse a client</option>
</select>
如果用户更改了下拉列表的值并且添加了该值,那么我想在我的jsp页面中执行以下查询:
String query = "SELECT * FROM CLIENT ORDER BY CID DESC";
ResultSet result = s.executeQuery(query);
while(result.next()) {
out.print("<option value=" + result.getString("CID") + ">");
out.print(result.getString("Name") + " (" + result.getString("CID")+")");
out.print("</option>\n");
}
如果用户选择退出,则不同的查询已执行,我该怎么做?基本上,从 jQuery 的角度来看,我想要的是它可以更改 select 选项上 onChange 事件的 query
值并运行executeQuery
I am currently using jsp and I wanted to create a dynamic drop down list. When the page first loads I have this drop down list:
<select name="target" id="target">
<option value="">--Select an option--</option>
<option value="add">Add a client with a program</option>
<option value="exit">Mark a client as exit client</option>
<option value="refuse">Refuse a client</option>
</select>
If on a user changes the value of the drop down and the value is add then I would like to execute the following query in my jsp page:
String query = "SELECT * FROM CLIENT ORDER BY CID DESC";
ResultSet result = s.executeQuery(query);
while(result.next()) {
out.print("<option value=" + result.getString("CID") + ">");
out.print(result.getString("Name") + " (" + result.getString("CID")+")");
out.print("</option>\n");
}
if the user choose's exit then a different query is executed, how can I do this? Basically what I want from the jQuery perspective is so it can change the query
value on an onChange event on the select option and run executeQuery
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的 Java 脚本放置在不同的页面中,假设 request_handler.jsp 并使用 JQUERY AJAX 方法将请求发送到该页面并返回包含新标签及其值的新页面。然后使用 $("target").html(new_html) 之类的内容替换旧值。
Place your Java script in a different page assume request_handler.jsp and Use JQUERY AJAX method to send request to that page and return a new page with fresh tags and their values. Then use something like $("target").html(new_html) to replace the old values.