jsp中如何实现下拉框二级联动
答案:4 悬赏:10 手机版
解决时间 2021-01-19 01:58
- 提问者网友:最美的风景
- 2021-01-18 19:14
jsp中如何实现下拉框二级联动
最佳答案
- 五星知识达人网友:冷風如刀
- 2021-01-18 19:28
参考下列代码:
< 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>
< 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
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
change(0);
}
//-->
< /script>
< /head>
< body onload="setup()">
< form name="frm">
< select id="s1">
< select id="s2">
< /form>
< /body>
< /html>
全部回答
- 1楼网友:妄饮晩冬酒
- 2021-01-18 21:47
数据写到两个js数组里就可以
- 2楼网友:零点过十分
- 2021-01-18 20:55
静态的非常简单,用javascript写个onchnage()事件就搞定了。
祝好运!---------^-^臭即是香^-^!
祝好运!---------^-^臭即是香^-^!
- 3楼网友:佘樂
- 2021-01-18 20:20
你这个是静态的还是从数据库查的?
如果是静态的 网上很多例子, 把数据写到两个js数组里就可以了
如果是动态的,一般用的是Ajax来做,如果你觉得这个比较难,那么我给你个简单的思路
就是当我选择第一个下拉菜单的时候,触发onchange事件 提交表单,把选择的value提交到servlet
然后通过这个value把第二个下拉菜单要显示的内容查出来,再传到这个页面上显示
如果是静态的 网上很多例子, 把数据写到两个js数组里就可以了
如果是动态的,一般用的是Ajax来做,如果你觉得这个比较难,那么我给你个简单的思路
就是当我选择第一个下拉菜单的时候,触发onchange事件 提交表单,把选择的value提交到servlet
然后通过这个value把第二个下拉菜单要显示的内容查出来,再传到这个页面上显示
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯