求一个jsp的小例子,即填写表单时可以弹出一个小网页,添加表单中下拉列表的选项
求一个jsp的小例子,即填写表单时可以弹出一个小网页,添加表单中下拉列表的选项,同时锁定父窗口,弹出的小网页提交后刷新父窗口的下拉框,出现新添加的选项,最好刷新能不丢失之前输入的表单数据
以前注册论坛时经常看到类似的功能,现在做一个页面需要用这个,谁能提供个例子或视频教程,思路也可以,越简单越好~
------解决方案--------------------关键有两点:
1、弹窗,锁定父窗口·这个JS效果自己去网上搜
2、下拉列表联动·这里应用AJAX··代码提出来你估计也看不懂··还是建议多去Google·
------解决方案--------------------
简单按你的要求做了下,如果是你想要的功能,你就自己完善吧...困死了,明天还要上班....
两个页面父页面和子页面:只是简单js+html实现,
parent.jspHTML code
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'parent.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function addCity() {
var str = window.showModalDialog("child.jsp", null,
"dialogWidth=400px;dialogHeight=200px");
var option = document.createElement('option');
option.text = str[0];
option.value = str[1];
var mySelect = document.getElementById("mySelect");
try {
mySelect.add(option, null); // standards compliant
} catch (ex) {
mySelect.add(option); // IE only
}
}
</script>
</head>
<body>
<form action="#">
所在城市:
<select id="mySelect">
<option value="010">
北京
</option>
</select>
<input type="button" value="增加城市" onclick="addCity();">
</form>
</body>
</html>