jsp页面怎么实现下拉框联动....

很急的 项目要交了 麻烦你帮下我..谢谢 了
2024-11-06 19:19:37
推荐回答(4个)
回答1:

两种方案

一个是用JavaScript,一次性将两个select的数据统统取出来,将第二张表的数据放到数组中,通过第一个的change事件来改变,优点,运行速度快,缺点,需编写对应的javascript代码,且无法反映实时数据

第二种方案是每次都提交,进行正液联动,优点,能反映数据库实时数据信息,无须写javascript,缺点,运行速度相对慢,且需要考虑保存用户的已经填写的其他表单数据

看我的,方便







<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>

<%
String las =request.getParameter("la");
String ars =request.getParameter("ar");
%>









<举态物/form>



闭乎










部门:

员工:








回答2:

这个只能用ajax实现 我那本ajax书碧培上就讲了这个实例 叫二级联动(甚至三级 四级... 都滚慧毁是一样的思路)大备

回答3:

参考下列代码:

< head>
< title>多级关联菜单
< meta http-equiv="Content-Type" content="text/html; charset=gb2312">
< head>
< script language="JavaScript">
< !--
function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;i var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i if(v)options[1].selected = true;
}
}
if(++v }
}
var dsy = new Dsy();
dsy.add("0",["安徽","北京","福建","甘肃","广东","广西","贵州","海南","河北","河南","黑龙江","湖北","湖南","吉林","江苏","江西","坦余辽宁","内蒙古","宁夏","青海","山东","山西","陕西","上海","四川","天津","西藏","新疆","云南","浙江","重庆"]);
dsy.add("0_0",["安庆","蚌埠","巢湖","池州","滁州","阜阳","合肥","亮中淮北","淮南","黄山","六安","马鞍山","宿州","铜陵","芜湖","宣城","亳州"]);
//-->
< /script>
< script language = JavaScript>
< !--
var s=["s1","s2","s3"];
var opt0 = ["-省-","-市-"];
function setup()
{
for(i=0;i document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
//-->
< /script>
< /head>
< body onload="setup()">
< form name="frm">
< select id="s1">
< select id="s2">
< /form>
< /body>
< /html>

回答4:

调下分辨率