设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 77|回复: 7
打印 上一主题 下一主题

[求助]二级连动.急

[复制链接]
跳转到指定楼层
1#
发表于 2010-1-8 00:59:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教大家一个二级菜单联动的代码.我做了一个二级连动.大类是定了,想要显示小类,需要获取大类.但是再不提交表单的情况下怎么能获取到大类的内容??请大家们给看看~!谢谢,代码如下

<!--#include file="conn.asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.STYLE1 {color: #000000;
font-weight: bold;
}
.style4 {color: #FF0000}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
.F12 {
font-size: 12px;
font-weight: normal;
color: #000000;
}
a:active {
text-decoration: none;
}
.F14 {
font-size: 12px;
font-weight: 600;
color: #000000;
}
-->
</style>
<table width="98%" border="5" align="center" cellpadding="5" cellspacing="5" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
<tr>
<td height="16" background="images/topbg.gif"><span class="F14">您现在所在的位置是:</span> <span class="F14"><a href="admin.asp" class="F14">管理首页</a> -&gt;</span><span class="STYLE1"> <span class="F14">网站基本设置</span></span></td>
</tr>
<tr>
<td height="107" valign="top" bgcolor="#FFFFFF"> <br>
<form id="form1" name="form1" method="post" action="Pz_Update.asp">
<table width="98%" border="2" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#CCCCCC">
<%
Dim Sql
set rs=server.CreateObject("adodb.recordset")
Sql="select * from SmallClass"
rs.Open Sql,conn,1,1
%>
<tr>
<td width="20%" align="right" background="images/topbg.gif" bgcolor="#f4f4f4"><strong class="F12">信息标题:</strong></td>
<td width="80%" bgcolor="#FFFFFF"><input name="News_Title" type="text" class="input_sr" id="News_Title" size="28" /></td>
</tr>
<tr>
<td align="right" background="images/topbg.gif" bgcolor="#f4f4f4"><strong class="F12">发布时间:</strong></td>
<td bgcolor="#FFFFFF"><input name="News_Time" type="text" class="input_sr" id="News_Time" size="28" /> </td>
</tr>
<tr>
<td align="right" background="images/topbg.gif" bgcolor="#f4f4f4"><strong class="F12">发布者:</strong></td>
<td bgcolor="#FFFFFF"><input name="News_Body" type="text" class="input_sr" id="News_Body" size="28" /> </td>
</tr>
<tr>
<td align="right" background="images/topbg.gif" bgcolor="#f4f4f4"><strong class="F12">所属大类:</strong></td>
<td bgcolor="#FFFFFF"><select name="BigClassName" size="1" id="BigClassName">
<option value="<%=rs("BigClassName")%>"><%=rs("BigClassName")%></option>
</select>
</td>
</tr>
<tr>
<td align="right" background="images/topbg.gif" bgcolor="#f4f4f4"><strong class="F12">所属小类:</strong></td>
<td bgcolor="#FFFFFF"><select name="SmallClassName" id="SmallClassName">
</select></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#F4F4F4"><strong class="F12">公司简介:</strong></td>
<td bgcolor="#FFFFFF"><input type="hidden" name="content" value="">
</textarea>
<iframe id="content" src="edit/ewebeditor.asp?id=content&amp;style=news" frameborder="0" scrolling="No" width="550" height="350" marginwidth="1" marginheight="1" name="content"></iframe></td>
</tr>
<tr>
<td height="22" colspan="2" align="center" bgcolor="#F4F4F4"><input name="Submit" type="submit" class="input_bot" value="提交" />
&nbsp;&nbsp;
<input name="Submit2" type="reset" class="input_bot" value="重置" /> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>

</body>
</html>
2#
发表于 2010-1-8 00:59:34 | 只看该作者
用事件你试了吗?
回复 支持 反对

使用道具 举报

3#
发表于 2010-1-8 00:59:37 | 只看该作者
帮忙指点一下  谢谢~!
回复 支持 反对

使用道具 举报

4#
发表于 2010-1-8 00:59:40 | 只看该作者
这么巧啊,我这两天也在研究二级联动。现在有事,晚点再来
回复 支持 反对

使用道具 举报

5#
发表于 2010-1-8 00:59:44 | 只看该作者
<span onclick="inti(0)">
<select name=azone id="azone" onChange="this.value=this.options[this.selectedIndex].value;altcls();inps.value=optn.options[0].value;">
<option value="省份" disabled="disabled">省份</option>
</select>
<select name=cls id="cls" onChange="if(this.options[0].text!='选择城区')inps.value=this.options[this.selectedIndex].value;">
<option value=0>选择城区</option>
</select>
<input type="text" id="inps" name="inps" size="5" value="" onkeyup="if(this.value.length>1)inti(0);findarea();">
</span>

<span onclick="inti(1)">
<select name=azone id="azone1" onChange="this.value=this.options[this.selectedIndex].value;altcls();inps.value=optn.options[0].value;">
<option value="省份" disabled="disabled">省份</option>
</select>
<select name=cls id="cls1" onChange="if(this.options[0].text!='选择城区')inps.value=this.options[this.selectedIndex].value;">
<option value=0>选择城区</option>
</select>
<input type="text" id="inps1" name="inps" size="5" value="" onkeyup="if(this.value.length>1)inti(1);findarea();">
</span>
<script>
var areaList={
"北京":[["选择城区","10"],["东城区",""],["西城区",""],["崇文区",""],["宣武区",""],["朝阳区",""],["丰台区",""],["石景山区",""],["海淀区",""],["门头沟区",""],["房山区",""],["通州区",""],["顺义区",""],["延庆县",""],["昌平县",""],["怀柔县",""],["密云县",""],["平谷县",""],["大兴县",""]],
"天津":[["选择城区","22"],["和平区",""],["河东区",""],["河西区",""],["南开区",""],["河北区",""],["红桥区",""],["塘沽区",""],["大港区",""],["汉沽区",""],["东丽区",""],["西青区",""],["津南区",""],["北辰区",""],["蓟县","22"],["宝坻县",""],["武清县",""],["宁河县",""],["静海县",""]],
"上海":[["选择城区","21"],["南市区",""],["卢湾区",""],["徐汇区",""],["长宁区",""],["静安区",""],["普陀区",""],["闸北区",""],["虹口区",""],["杨浦区",""],["闵行区",""],["宝山区",""],["嘉定区",""],["浦东新区",""],["金山区",""],["松江区",""],["崇明县",""],["青浦县",""],["南汇县",""],["奉贤县",""],["黄浦区",""]],
"重庆":[["选择城区","23"],["重庆市",""],["城口县",""],["大足县",""],["垫江县",""],["丰都县",""],["奉节县",""],["河川市",""],["江津市",""],["开县","23"],["梁平县",""],["南川市",""],["彭水苗族土家族自治县",""],["荣昌县",""],["石柱土家族自治县",""],["铜梁县",""],["巫山县",""],["巫溪县",""],["武隆县",""],["秀山土家苗族自治区",""],["永川市",""],["酉阳土家苗族自治区",""],["云阳县",""],["忠县","23"],["潼南县",""],["碧山县",""],["綦江县",""]],
"香港":[["选择城区","0852"],["香港",""],["九龙",""],["新界",""],["大屿",""]],
"澳门":[["选择城区","0853"],["澳门",""]],
"西藏":[["阿里","8073"],["昌都","895"],["拉萨","891"],["林芝","894"],["那曲","896"],["日喀则","892"],["山南","893"]],
"新疆":[["阿克苏","997"],["阿拉尔","997"],["巴音郭楞蒙古自治州",""],["博尔塔拉蒙古自治州",""],["昌吉回族自治州",""],["哈密","902"],["和田","903"],["喀什",""],["克拉玛依","990"],["克孜勒苏柯尔克孜自治州",""],["石河子","993"],["图木舒克",""],["吐鲁番","995"],["乌鲁木齐","991"],["奎屯","992"],["五家渠",""],["伊犁哈萨克自治州",""]],
"内蒙古":[["阿拉善盟",""],["巴彦淖尔盟",""],["包头","472"],["赤峰","476"],["呼和浩特","471"],["呼伦贝尔",""],["通辽","475"],["乌海","473"],["乌兰察布盟",""],["锡林郭勒盟",""],["兴安盟",""],["鄂尔多斯",""]],
"广西":[["百色","776"],["北海","779"],["崇左","771"],["防城港","770"],["桂林","773"],["贵港","775"],["河池","778"],["贺州",""],["来宾","772"],["柳州","772"],["南宁","771"],["钦州","777"],["梧州","774"],["玉林","775"]],
"宁夏":[["固原","954"],["石嘴山","952"],["吴忠","953"],["银川","951"]],
"山西":[["长治","355"],["大同","352"],["晋城","356"],["晋中",""],["临汾","357"],["吕梁",""],["朔州","349"],["太原","351"],["忻州","350"],["阳泉","353"],["运城","359"]],
"河南":[["安阳","372"],["鹤壁","392"],["济源","391"],["焦作","391"],["洛阳","379"],["南阳","377"],["开封","378"],["平顶山","375"],["三门峡","398"],["商丘","370"],["信阳","376"],["新乡","373"],["许昌","374"],["郑州","371"],["周口","394"],["驻马店","396"],["漯河","395"],["濮阳","393"]],
"河北":[["保定","312"],["沧州","317"],["邯郸","310"],["承德","314"],["衡水","318"],["秦皇岛","335"],["廊坊","316"],["石家庄","311"],["唐山","315"],["邢台","319"],["张家口","313"]],
"江西":[["抚州","794"],["赣江",""],["吉安","796"],["景德镇","798"],["九江","792"],["南昌","791"],["上饶","793"],["萍乡","799"],["新余","790"],["宜春","795"],["鹰潭","701"]],
"湖南":[["常德",""],["长沙",""],["郴州",""],["衡阳",""],["怀化",""],["娄底",""],["邵阳",""],["湘潭",""],["湘西土家族苗族自治州",""],["益阳",""],["永州",""],["岳阳",""],["张家界",""],["株洲",""]],
"江苏":[["常州","519"],["连云港","518"],["淮安","517"],["南京","25"],["南通","513"],["苏州","512"],["宿迁","527"],["泰州","523"],["无锡","510"],["徐州","516"],["盐城","515"],["扬州","514"],["镇江","511"]],
"浙江":[["杭州","571"],["湖州","572"],["嘉兴","573"],["金华","579"],["丽水","578"],["宁波","574"],["绍兴","575"],["台州","576"],["温州","577"],["舟山","580"],["衢州","570"]],
"安徽":[["安庆","556"],["蚌埠","552"],["巢湖","565"],["池州",""],["滁州","550"],["阜阳","558"],["合肥","551"],["淮北","561"],["淮南","554"],["黄山","559"],["六安","564"],["马鞍山","555"],["宿州","557"],["铜陵","562"],["芜湖","553"],["宣城",""],["亳州","558"]],
"湖北":[["鄂州","711"],["恩施土家族苗族自治州",""],["黄冈","713"],["黄石","714"],["荆门","727"],["荆州",""],["神农架林区",""],["潜江","728"],["十堰","719"],["随州","722"],["天门","728"],["武汉","27"],["咸宁","715"],["仙桃",""],["襄樊","710"],["孝感","712"],["宜昌","717"]],
"黑龙江":[["大庆","459"],["大兴安岭",""],["哈尔滨","451"],["鹤岗","454"],["黑河","456"],["鸡西","453"],["佳木斯","454"],["牡丹江","453"],["七台河","453"],["齐齐哈尔","452"],["双鸭山","454"],["绥化 ",""],["伊春","458"]],
"吉林":[["白城","436"],["白山",""],["长春","431"],["吉林","431"],["辽源","437"],["四平","434"],["松原","438"],["通化","435"],["延边朝鲜族自治州",""]],
"辽宁":[["鞍山","555"],["本溪","414"],["朝阳","421"],["大连","456"],["丹东","415"],["抚顺","413"],["阜新","418"],["葫芦岛","429"],["锦州","416"],["辽阳","419"],["盘锦","427"],["沈阳","24"],["铁岭","410"],["营口","417"]],
"陕西":[["安康","915"],["宝鸡","917"],["汉中","916"],["商洛",""],["铜川","919"],["西安","29"],["渭南","913"],["咸阳","910"],["延安","911"],["榆林","912"]],
"甘肃":[["白银","943"],["定西","932"],["甘南藏族自治区",""],["嘉峪关","937"],["金昌","935"],["酒泉","937"],["兰州","931"],["临夏回族自治区",""],["陇南",""],["平凉","943"],["庆阳","9441"],["天水","938"],["武威",""],["张掖","936"]],
"青海":[["果洛藏族自治州",""],["海北藏族自治州",""],["海东",""],["海南藏族自治州",""],["海西蒙古族藏族自治州",""],["黄南藏族自治州",""],["西宁","971"],["玉树藏族自治州",""]],
"云南":[["保山","875"],["楚雄彝族自治州",""],["大理白族自治州",""],["德宏傣族景颇族自治州",""],["迪庆藏族自治州",""],["红河哈尼族彝族自治州",""],["昆明","871"],["丽江","888"],["临沧","883"],["怒江傈僳族自治州",""],["曲靖","874"],["思茅","879"],["文山壮族苗族自治州",""],["西双版纳傣族自治州",""],["玉溪","877"],["昭通","870"]],
"贵州":[["安顺","853"],["毕节","857"],["贵阳","851"],["六盘水","858"],["黔东南苗族侗族自治州",""],["黔南布依族苗族自治州",""],["铜仁","856"],["遵义","852"],["黔西南布依族苗族自治州",""]],
"四川":[["阿坝藏族羌族自治州",""],["巴中","8279"],["德阳","838"],["成都","28"],["达州",""],["甘孜藏族自治州",""],["广安","826"],["广元","839"],["乐山","833"],["凉山彝族自治州",""],["眉山","833"],["绵阳","816"],["南充","817"],["内江","832"],["攀枝花","812"],["遂宁","825"],["雅安","835"],["宜宾","831"],["资阳","832"],["自贡","813"],["泸州","830"]],
"福建":[["福州","591"],["龙岩","597"],["南平","599"],["宁德","593"],["莆田","594"],["泉州","595"],["三明","598"],["漳州","596"],["厦门","592"]],
"山东":[["滨州","543"],["德州","534"],["东营","546"],["荷泽","530"],["济南","531"],["济宁","537"],["莱芜","634"],["聊城","635"],["临沂","539"],["青岛","532"],["日照","633"],["泰安","538"],["威海","631"],["潍坊","536"],["烟台","535"],["枣庄","632"],["淄博","533"]],
"广东":[["潮州","768"],["东莞","769"],["佛山","757"],["广州","20"],["河源","762"],["江门","750"],["揭阳","663"],["惠州","752"],["茂名","668"],["梅州","753"],["清远","763"],["汕头","754"],["汕尾","660"],["韶关","751"],["深圳","755"],["阳江","662"],["云浮","766"],["湛江","759"],["肇庆","758"],["中山","760"],["珠海","756"]],
"海南":[["白沙黎族自治县",""],["保亭黎族苗族自治县",""],["昌江黎族自治县",""],["澄迈县",""],["定安县",""],["海口","898"],["东方","890"],["乐东黎族自治县",""],["临高县",""],["陵水黎族自治县",""],["琼海","898"],["琼中黎族苗族自治县",""],["三亚","899"],["屯昌县",""],["万宁","898"],["文昌","898"],["五指山",""],["儋州","890"]],
"台湾":[["台北市",""],["高雄市",""],["台南市",""],["台中市",""],["基隆",""],["新竹",""]],
"海外华人":[["北美华人",""],["南美华人",""],["澳洲华人",""],["亚洲华人",""],["欧洲华人",""],["非洲华人",""]],
"各国外宾":[["北美外宾",""],["南美外宾",""],["澳洲外宾",""],["亚洲外宾",""],["欧洲外宾",""],["非洲外宾",""]],
"其它":[["其它","00"]]
};
var sk=0;
var fd=0;
var skk;
var ix=0;
var sx=0;
var sf=document.getElementById("azone");
var optn=document.getElementById("cls");
var inps=document.getElementById('inps');
function inti(n){
sk=0;
fd=0;
if(n==0){
sf=document.getElementById("azone");
optn=document.getElementById("cls");
inps=document.getElementById('inps');
sx=12;ix=14;
}
if(n==1){
sf=document.getElementById("azone1");
optn=document.getElementById("cls1");
inps=document.getElementById('inps1');
sx=9;ix=4;
}
if(sf.options.length<2){for(name in areaList){
sf.options[sk++]=new Option(name,name);
}}
return true;
}
window.onload=function(){
for(nx=0;nx<2;nx++){
inti(nx);
sf.selectedIndex=sx;
sf.value=sf.options[sf.selectedIndex].value;
altcls();
optn.selectedIndex=ix;
optn.value=optn.options[optn.selectedIndex].value;
inps.value=optn.options[optn.selectedIndex].value;
}
}
function altcls(){
var tmpcls=areaList[sf.value];
var fs=0;
optn.innerHTML='';
if(sf.value=="省份"){
optn.options[0]=new Option("←选左边",0);
}else{
try{if(tmpcls[0][0].indexOf("选择城区")!=-1)fs++;}catch(e){}
optn.options[0]=new Option("选取地区",0);
optn.options[0].disabled="disabled";optn.options[0].style.color="#060";
for(i=0;i<tmpcls.length;i++){
if(typeof(tmpcls[i][0])!="undefined"&&tmpcls[i][0].length>1){
optn.options[i]=new Option(tmpcls[i][0],"0"+tmpcls[i][1]);
if("0"+tmpcls[i][1]==inps.value){
optn.selectedIndex=i;fd=1;if((++fs)==2){optn.selectedIndex=0;fs=1;}}
}else{optn.options[i]=new Option(tmpcls[i],tmpcls[i]);
}
}
}
return;
}
function findarea(){
sk=0;
if(inps.value.substring(0,1)>0)inps.value="0"+inps.value;
for(name in areaList){
sf.options[sk++]=new Option(name,name);
sf.value=sf.options[sk-1].value;
altcls();
if(fd==1){fd=0;sf.selectedIndex=sk-1;break;}
}
}
</script>
在给你一个看下吧 这个直接拿出去就能看效果了
回复 支持 反对

使用道具 举报

6#
发表于 2010-1-8 00:59:47 | 只看该作者
javscript   我不会用`!
回复 支持 反对

使用道具 举报

7#
发表于 2010-1-8 00:59:51 | 只看该作者
Province(省)
具体字段:id—自动编号 ProvinceName—省名 ProvinceNo—省名编号 ProvinceOrder—省排序编号
省 id ProvinceName ProvinceNo ProvinceOrder
1 北京市 0 0
2 安徽省 1 1
3 山东省 2 2
4 江苏省 3 3

以下省名略。
设计思想:id是表的自动编号,ProvinceName和ProvinceNo是必须的,前者是用来存储省名,后者则是联系表city必不可少的字段。至于ProvinceOrder则是用来给省名排序的,控制下拉列表中省名出现的位置,可以省略。
City(城市)
具体字段:id—自动编号 CityName—市名 CityNo—市名编号 CityOrder—市排序编号 ProvinceID—所在省编号
市 id
CityName
CityNo
CityOrder
ProvinceID
1
北京市
1
1
0
2
合肥市
2
2
1
3
芜湖市
3
3
1
4
安庆市
4
4
1
5 济南市
5
5
2
6 青岛市
6
6
2
以下市名略。
设计思想:前面四项同Province表设计思想,ProvinceID字段将Province表和City表联系起来。
2.设计样式及编码
二级联动的样式很简单,在DreamWeaver 2004里向设计页面上放置两个select下拉菜单,分别取名为Province_select、City_select,它们都在名为form1的表单里。
编码需要用到html、vbscript及javascript。首先是连接数据库,我们用常用的<!--#include file="conn.asp"-->连接。conn.asp中代码略。
其次,用Javascript和Vbscript将Province和City表中的数据读出来并使Province_select和City_select联系起来,这一步是整个程序的关键所在。
代码如下:
<script language=JavaScript>
<%
dim sql,i,j
'//////////////////////////读出 Province 表//////////////////////////
set rs_Province=server.createobject("adodb.recordset")
sql="select * from Province order by ProvinceOrder"
rs_Province.open sql,conn,1,1
%>

var selects=[];
selects['xxx']=new Array(new Option('请选择城市……','xxx'));

<%
for i=1 to rs_s.recordcount
%>

selects['<%=rs_Province("ProvinceNo")%>']=new Array(
<%
'//////////////////////////读出 City 表//////////////////////////
set rs_City=server.createobject("adodb.recordset")
sql="select * from City where ProvinceID="&rs_Province("id")&" order by ProvinceOrder"
rs_City.open sql,conn,1,1
if rs_City.recordcount>0 then
for j=1 to rs_City.recordcount
if j=rs_City.recordcount then
%>

new Option('<%=trim(rs_City("CityName"))%>','<%=trim(rs_City("CityNo"))%>'));

<%else%>

new Option('<%=trim(rs_City("Cityname"))%>','<%=trim(rs_City("CityNo"))%>'),

<%
end if
rs_City.movenext
next
else
%>
new Option('','0'));

<%
end if
rs_City.close
set rs_City=nothing
rs_Province.movenext
next
rs_Province.close
set rs_Province=nothing
%>

<!--//////////JavaScript控制联动///////////-->
function chsel(){
with (document.form1){
if(province_select.value) {
city_select.options.length=0;
for(var i=0;i<selects[province_select.value].length;i++){
city_select.add(selects[province_select.value][i]);
}
}
}
}
</script>
最后,结合html,Javascript和Vbscript实现联动效果。代码如下:
<!--//////////////////////////Province_select下拉列表//////////////////////////-->
<select name="Province_select" onChange=chsel()>
<option value="xxx" selected>请选择省份……</option>
<%
dim tmpid '定义一个临时变量用来记住省id
tmpid=0
set rs_Province=server.CreateObject("ADODB.recordset")
sql="select * from Province order by ProvinceOrder"
rs_Province.open sql,conn,1,1
while not rs_Province.eof
tmpid=rs_Province("id")
%>
<option value="<%=rs_Province("ProvinceNo")%>" ><%=trim(rs_Province("ProvinceName"))%></option>
<%
rs_Province.movenext
wend
rs_Province.close
set rs_Province=nothing
%>
</select>
<!--//////////////////////////City_select下拉列表//////////////////////////-->
<select name="City_select">
<%
set rs_City=server.createobject("adodb.recordset")
sql="select * from City where ProvinceID="&tmpid&" order by CityOrder"
rs_City.open sql,conn,1,1
while not rs_City.eof
%>
<option value="<%=rs_City("CityNo")%>"><%=trim(rs_City("CityName"))%></option>
<%
rs_City.movenext
wend
rs_City.close
set rs_City=nothing
%>
</select>
回复 支持 反对

使用道具 举报

8#
发表于 2010-3-8 14:05:04 | 只看该作者
那个贴子 让它沉下去吧! 不要啦
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-19 06:33 , Processed in 0.113035 second(s), 10 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表