高手看看:如果不是每次都是从数据库中取数据,如何实现以下的功能呢?实现不行的话只能每次取数据库拉:(

ZHANGWEI15 2004-11-05 02:50:44
高手看看:如果不是每次都是从数据库中取数据,改如何实现以下的功能呢?

后台数据中表如下
表a
id value
1 100
2 200
3 300


表b
id subid value
1 1 a
1 2 b
1 3 c
3 1 e
3 2 f


前台有两个select标签分别装载表a和表b,
<select id="a">
<select id="b">
我需要选择a下拉框的时候,b中能显示相应的信息
比如
a选择了100,b出现,则b中的信息为abc,
a选择了300,b出现,则b中的信息为ef
a选择了200,b不出现...


我想通过javascript来实现这个功能,因为不大熟悉js,请问大家能否实现呢?
主要难点:
1.如何动态控制b的下拉列表中的值?
2.如何动态控制b的是否出现?
网上看了点例子觉得后台的结构不大一样,请大家给点思路实现的代码可以吗?谢谢!





...全文
117 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
maatcat 2004-11-05
  • 打赏
  • 举报
回复
我这儿有个类似的,可以看看(在网上下的)

<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; c
harset=gb2312">
<script LANGUAGE="javascript">
<!--
var onecount;
onecount=0;

subcat = new Array();
subcat[0] = new Array("徐汇区","01","001");
subcat[1] = new Array("嘉定区","01","002");
subcat[2] = new Array("黄浦区","01","003");
subcat[3] = new Array("南昌市","02","004");
subcat[4] = new Array("九江市","02","005");
subcat[5] = new Array("上饶市","02","006");

onecount=6;

function changelocation(locationid)
{
document.myform.smalllocation.length = 0;

var locationid=locationid;
var i;
document.myform.smalllocation.options[0] = new Option('====所有地区====','');
for (i=0;i <onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.smalllocation.options[document.myform.smalllocation.length]
= new Option(subcat[i][0], subcat[i][2]);
}
}

}
</script>
</head>
<body>
<form name="myform" method="post">
<select name="biglocation"
onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)">
<option value="01" selected>上海</option>
<option value="02">江西</option>
</select>
<select name="smalllocation">
<option selected value="">==所有地区==</option>
</select>
</form>
<script LANGUAGE="javascript">
<!--
changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value);
//-->
</script>
</body>
</html>

ZHANGWEI15 2004-11-05
  • 打赏
  • 举报
回复
谁能给点实现类似功能的关键的javascript方法
或者思路吗?
life360 2004-11-05
  • 打赏
  • 举报
回复
你找一下 js 的联动就可以了,一次把所有数据读出来
DeltaCat 2004-11-05
  • 打赏
  • 举报
回复
搜一下 "联动" 有很多啊

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧