怎样使两个下拉菜单相互关联?数据是从数据库中读取的!! 不难,在第一个select 用onchange="send()"<script >function send(){document.form1.submit()}刷新页面,将数据添入第二个select. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是说你这里有两个步骤:一是从数据库中取销售阶段表的数据,二是让第二个下拉菜单发生变化。 我觉得这样的流程如果不提交页面是很难实现的。有个办法可以实现你的要求,不过可能会影响速度: 页面初始化时把数据库中所有销售流程表和销售阶段表中的数据都load进来,然后用javascript把它们放在数组中,用来对应第二个下拉菜单中的内容,每次选择第一个下拉菜单时,用相应的数组元素来显示第二个下拉菜单就可以了。 这中方法初始化时可能会比较慢,但是肯定可行,我以前做过类似的菜单。 一级分类从数据库生成,并在其select的onchange事件中改变二级分类的select每个一级分类所对应的二级分类列表可存在一个数组中,当一级分类改变时,在onchange事件中将二级分类的select清空,根据对应的数组重新生成二级分类列表.举个例子:员工信息中部门和职务为一对多的关系,我做成了动态下拉框的形式,点击部门下拉框,职务下拉框会变为对应的所属职务,我的动态下拉框的实现方法:从数据库中把每个部门对应的职务取出来,存为不同的数组,当部门下拉框onchange时,就把对应的职务数组里的值付给职务下拉框,就可以了)<script language="javascript">var postname=new Arrayvar postid=new Arrayvar deptid=new Arrayvar space=new Arrayfunction change_array(array1,array2,array3) { postname=array1.split("|"); postid=array2.split("|"); deptid=array3.split("|"); space='|'.split("|");}function changepost(a) {// alert (a);var num1;var i=0;var h=1;for (loop=0; loop < postname.length; loop++) { if (deptid[loop]==a) { i++; }}//alert (i);window.document.add.Ba01_post.options.length = i+1; //-------------给职务选择框赋值---------------- add.Ba01_post.options[0].text = '------请选择------'; add.Ba01_post.options[0].value = '';for (loop=0; loop < postname.length; loop++) { if (deptid[loop]==a){// alert ('aaa'); add.Ba01_post.options[h].text = postname[loop]; add.Ba01_post.options[h].value = postid[loop]; h++ }}}function swapOptions(the_array_name){//把符合the_array_name的数组值赋给the_array.var the_array = eval(the_array_name);//setOptionText(操作的对象选择框,对象数组)setOptionText(window.document.add.IP06_No, the_array);}function setOptionText(the_select, the_array){the_select.options.length = the_array.length-1;for (loop=0; loop < the_array.length-1; loop++) { the_select.options[loop].text = the_array[loop]; the_select.options[loop].value = the_array[loop]; }}</script><%'-----------------------定义二维数组用来实现部门与职务的对应关系------------------------set postrs=SERVER.CREATEOBJECT("ADODB.RECORDSET")postsql="select sys02_deptid,sys02_postid,sys02_postname from sys02_post"postrs.open postsql,conn,3,1postname=""postid=""deptid=""for i=1 to postrs.recordcount if i=postrs.recordcount then postname=postname+postrs("sys02_postname") postid=postid&postrs("sys02_postid") deptid=deptid&postrs("sys02_deptid") else postname=postname+postrs("sys02_postname")+"|" postid=postid&postrs("sys02_postid")&"|" deptid=deptid&postrs("sys02_deptid")&"|" end if postrs.movenextnext'response.write postname&"<br>"'response.write postid&"<br>"'response.write deptid&"<br>"'---------------------------------------------------------------------------------------%><html><body onload="change_array('<%=postname%>','<%=postid%>','<%=deptid%>');"><form method=POST name=add LANGUAGE=javascript onsubmit="return add_onsubmit(this)" enctype="multipart/form-data" action="Ba_baseinfo_join.asp?save">工作部门:<select name="dept" onchange="changepost(this.value)"> <option>请选择</option><!--中间的从数据库中生成--> </select>职务:<select name="Ba01_post"><option value="">------请选择-------</option></select></form>基本上就是这些,你根据自己的数据表改一下。 不用提交一样可以关联:3级的!你稍微动一下就是2级的了:一個錶中有3個類別classsname classs classss 主類別|次類別|次次類別|(均為字符類型)現在我要用SELECT做成三級動態下拉菜單!用XML來作的!測試通過!<HTML><META NAME="save" CONTENT="history"/><script>function AttachXMLForSelect(xd,arr,defaultText,defaultValue)//xd:xmldom,arr:array of select{ function EnsureString(str) { if(typeof(str)=="string")return str; if(str==null)return ""; try{return str+"";}catch(x){} return ""; } function EnsureInt(i) { if(typeof(i)=="i")return i; try{i=parseInt(i);}catch(x){return 0}; if(isNaN(i))return 0; return i; } defaultText=EnsureString(defaultText); defaultValue=EnsureString(defaultValue); if(xd==null||xd.documentElement==null||arr==null||arr.length==0) throw(new Error(-1,"invalid arguments")); (function(xmldom){ xd=new ActiveXObject("Microsoft.XMLDOM"); xd.loadXML(xmldom.xml); })(xd) for(var i=0;i<arr.length;i++) arr[i]={ uniqueID:arr[i].uniqueID , node:null , attach:false }; arr[0].node=xd.documentElement; ReAttachNode(0); var Controller={ HandleChange:HandleChange }; return Controller; function OnSelectChange(event) { HandleChange(event.srcElement); } function HandleChange(s) { for(var index=0;index<arr.length;index++) { if(s.uniqueID==arr[index].uniqueID) break; } var node=arr[index].node; if(index!=0) node.setAttribute("selectedIndex",s.selectedIndex); if(index<arr.length-1) { if(node) { var xns=node.selectNodes("item"); arr[index+1].node=xns.item(s.selectedIndex); } else arr[index+1].node=null; ReAttachNode(index+1); } } function ReAttachNode(index) { var node=arr[index].node; var pnode=null; if(index>0)pnode=arr[index].node; var s=document.getElementById(arr[index].uniqueID); s.innerHTML=""; if((node==null||node.selectNodes("item").length==0)&&defaultText) { var o=document.createElement("OPTION"); o.value=defaultValue; o.innerText=defaultText; s.appendChild(o); } if(node==null) { if(arr[index].attach) { s.detachEvent("onchange",OnSelectChange); arr[index].attach=false; } HandleChange(s); return; } if(arr[index].attach==false) { s.attachEvent("onchange",OnSelectChange); arr[index].attach=true; } var xns=node.selectNodes("item"); for(var i=0;i<xns.length;i++) { var o=document.createElement("OPTION"); o.value=EnsureString(xns.item(i).getAttribute("value")); o.innerText=EnsureString(xns.item(i).getAttribute("text")); s.appendChild(o); } var si=0; if(index!=0) si=EnsureInt(node.getAttribute("selectedIndex")); if(si==0)si="0"; if(s.options.length) s.selectedIndex=parseInt(si); HandleChange(s); }}</script><BODY> <% DbPath = SERVER.MapPath("xxx.mdb") Set conn = Server.CreateObject("ADODB.Connection") conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath %><XML id=oxml><item><%set rst=server.createobject ("adodb.recordset")sqlt="select distinct classname,classs,classss from chanpin"rst.open sqlt,conn,3,1name1=""//同一個錶中的三個相關聯的字段name2=""//同一個錶中的三個相關聯的字段name3=""//同一個錶中的三個相關聯的字段do while not rst.eof If name1<>rst("classname").Value Then If name1<>"" Then Response.Write "</item></item>" name1=rst("classname").Value Response.Write "<item text='"+rst("classname").Value+"' value='"+rst("classname").Value+"'>" name2="" End If if name2<>rst("classs") then If name2<>"" Then Response.Write "</item>" name2=rst("classs").Value Response.Write "<item text='"+rst("classs").Value+"' value='"+rst("classs").Value+"'>" Response.Write "<item text='ggg' value='yyyy'/>" name3="" end if if name3<>rst("classss") then name3=rst("classss").Value Response.Write "<item text='"+rst("classss").Value+"' value='"+rst("classss").Value+"'/>" end if rst.movenextlooprst.close%></item></item></item></XML><SCRIPT>function AlertForm(f){ alert( "s1:\t"+GetSelectOption(f("s1")).innerText + "\t:\t" + GetSelectOption(f("s1")).value + "\r\n" + "s2:\t"+GetSelectOption(f("s2")).innerText + "\t:\t" + GetSelectOption(f("s2")).value + "\r\n" + "s3:\t"+GetSelectOption(f("s3")).innerText + "\t:\t" + GetSelectOption(f("s3")).value + "\r\n" ); return event.returnValue=false;}function GetSelectOption(s){ return s(s.selectedIndex);}</SCRIPT><FORM id=f1 onsubmit="AlertForm(this)"><SELECT name="s1" style="width:100px;"></SELECT><SELECT name="s2" style="width:100px;"></SELECT><SELECT name="s3" style="width:100px;"><!-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@//将上面的<SELECT name="s3" style="width:100px;">修改为<SELECT name="s3" style="display:none;width:100px;" >就变成二级别的了@~@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@--></SELECT><INPUT type="submit"></FORM><input type=hidden id=inpSave style="behavior:url(#default#savehistory)" value="0;0;0"></BODY><script>var C=AttachXMLForSelect(oxml.XMLDocument,[f1("s1"),f1("s2"),f1("s3")]);function window.onload(){ var sis=inpSave.value; var arr=sis.split(";"); f1("s1").selectedIndex=parseInt(arr[0]); C.HandleChange(f1("s1")); f1("s2").selectedIndex=parseInt(arr[1]); C.HandleChange(f1("s2")); f1("s3").selectedIndex=parseInt(arr[2]); C.HandleChange(f1("s3")); }function window.onbeforeunload(){ inpSave.value=""+f1("s1").selectedIndex+";"+f1("s2").selectedIndex+";"+f1("s3").selectedIndex;}</script></html> 我有办法,给我多少分呢?第一个页面:index.asp<script language="javascript">function loadasp(locationid){document.frames["hiddenframe"].location.replace("loadasp.asp?xslcid="+locationid);}</script><select name=xslc onchange="javascript:loadasp(this.value);"><option value=1>销售流程1<option value=1>销售流程2<option value=1>销售流程3</select><div id=divxsjdc><select name=xsjd><option value="">请选择</select></div><iframe id="hiddenframe" width="0" height="0"></iframe>loadasp.asp<%有ID,你可以通过asp的数据查询形成InnerString(HTML格式了,也就是xsjd的select的HTML代码)了,明白了吗?不明白,就发短消息给我%><HTML><BODY></BODY></HTML><script language="javascript"> parent.Div<%=intPCID%>.innerHTML = "<%=InnerString%>";</script> 点击让禁用的元素复原。 jquery问题 ms ie bug? 如何在新弹出的页面中打开一个本地的图片 怎么样使用javascript脚本感知网页已经拉到的最底端呢? 对象获取焦点 问题,请对事件比较了解的朋友帮忙解答一下呀,急用!!! 关于页面设计的一个问题? 很急,用button提交的问题 页面上有一个按钮,点击一下会通过jquery动态生成很多select,实现翻页后如何保留这些select? disabled 简单问题,戳进来指导一下 在页面间直接进行修改文本内容??。。。 怎样用纯脚本语言在客户端,实现树状结构资源管理,谢谢
我觉得这样的流程如果不提交页面是很难实现的。有个办法可以实现你的要求,不过可能会影响速度:
页面初始化时把数据库中所有销售流程表和销售阶段表中的数据都load进来,然后用javascript把它们放在数组中,用来对应第二个下拉菜单中的内容,每次选择第一个下拉菜单时,用相应的数组元素来显示第二个下拉菜单就可以了。
这中方法初始化时可能会比较慢,但是肯定可行,我以前做过类似的菜单。
每个一级分类所对应的二级分类列表可存在一个数组中,当一级分类改变时,在onchange事件中将二级分类的select清空,根据对应的数组重新生成二级分类列表.
举个例子:员工信息中部门和职务为一对多的关系,我做成了动态下拉框的形式,点击部门下拉框,职务下拉框会变为对应的所属职务,
我的动态下拉框的实现方法:
从数据库中把每个部门对应的职务取出来,存为不同的数组,当部门下拉框onchange时,就把对应的职务数组里的值付给职务下拉框,就可以了)<script language="javascript">
var postname=new Array
var postid=new Array
var deptid=new Array
var space=new Arrayfunction change_array(array1,array2,array3) {
postname=array1.split("|");
postid=array2.split("|");
deptid=array3.split("|");
space='|'.split("|");
}function changepost(a) {
// alert (a);
var num1;
var i=0;
var h=1;
for (loop=0; loop < postname.length; loop++)
{
if (deptid[loop]==a)
{
i++;
}
}
//alert (i);window.document.add.Ba01_post.options.length = i+1;
//-------------给职务选择框赋值----------------
add.Ba01_post.options[0].text = '------请选择------';
add.Ba01_post.options[0].value = '';for (loop=0; loop < postname.length; loop++)
{ if (deptid[loop]==a){
// alert ('aaa');
add.Ba01_post.options[h].text = postname[loop];
add.Ba01_post.options[h].value = postid[loop];
h++
}
}}function swapOptions(the_array_name)
{
//把符合the_array_name的数组值赋给the_array.
var the_array = eval(the_array_name);
//setOptionText(操作的对象选择框,对象数组)
setOptionText(window.document.add.IP06_No, the_array);
}function setOptionText(the_select, the_array)
{
the_select.options.length = the_array.length-1;
for (loop=0; loop < the_array.length-1; loop++)
{
the_select.options[loop].text = the_array[loop];
the_select.options[loop].value = the_array[loop];
}
}
</script>
<%
'-----------------------定义二维数组用来实现部门与职务的对应关系------------------------
set postrs=SERVER.CREATEOBJECT("ADODB.RECORDSET")
postsql="select sys02_deptid,sys02_postid,sys02_postname from sys02_post"
postrs.open postsql,conn,3,1
postname=""
postid=""
deptid=""
for i=1 to postrs.recordcount
if i=postrs.recordcount then
postname=postname+postrs("sys02_postname")
postid=postid&postrs("sys02_postid")
deptid=deptid&postrs("sys02_deptid")
else
postname=postname+postrs("sys02_postname")+"|"
postid=postid&postrs("sys02_postid")&"|"
deptid=deptid&postrs("sys02_deptid")&"|"
end if
postrs.movenext
next
'response.write postname&"<br>"
'response.write postid&"<br>"
'response.write deptid&"<br>"'---------------------------------------------------------------------------------------
%><html>
<body onload="change_array('<%=postname%>','<%=postid%>','<%=deptid%>');">
<form method=POST name=add LANGUAGE=javascript onsubmit="return add_onsubmit(this)" enctype="multipart/form-data" action="Ba_baseinfo_join.asp?save">工作部门:
<select name="dept" onchange="changepost(this.value)">
<option>请选择</option>
<!--中间的从数据库中生成-->
</select>
职务:
<select name="Ba01_post">
<option value="">------请选择-------</option>
</select>
</form>基本上就是这些,你根据自己的数据表改一下。
classsname classs classss
主類別|次類別|次次類別|(均為字符類型)
現在我要用SELECT做成三級動態下拉菜單!
用XML來作的!測試通過!<HTML>
<META NAME="save" CONTENT="history"/><script>
function AttachXMLForSelect(xd,arr,defaultText,defaultValue)//xd:xmldom,arr:array of select
{
function EnsureString(str)
{
if(typeof(str)=="string")return str;
if(str==null)return "";
try{return str+"";}catch(x){}
return "";
}
function EnsureInt(i)
{
if(typeof(i)=="i")return i;
try{i=parseInt(i);}catch(x){return 0};
if(isNaN(i))return 0;
return i;
}
defaultText=EnsureString(defaultText);
defaultValue=EnsureString(defaultValue);
if(xd==null||xd.documentElement==null||arr==null||arr.length==0)
throw(new Error(-1,"invalid arguments"));
(function(xmldom){
xd=new ActiveXObject("Microsoft.XMLDOM");
xd.loadXML(xmldom.xml);
})(xd)
for(var i=0;i<arr.length;i++)
arr[i]={
uniqueID:arr[i].uniqueID
,
node:null
,
attach:false
}; arr[0].node=xd.documentElement;
ReAttachNode(0); var Controller={ HandleChange:HandleChange }; return Controller; function OnSelectChange(event)
{
HandleChange(event.srcElement);
}
function HandleChange(s)
{
for(var index=0;index<arr.length;index++)
{
if(s.uniqueID==arr[index].uniqueID)
break;
} var node=arr[index].node;
if(index!=0)
node.setAttribute("selectedIndex",s.selectedIndex);
if(index<arr.length-1)
{
if(node)
{
var xns=node.selectNodes("item");
arr[index+1].node=xns.item(s.selectedIndex);
}
else arr[index+1].node=null; ReAttachNode(index+1);
}
} function ReAttachNode(index)
{
var node=arr[index].node;
var pnode=null;
if(index>0)pnode=arr[index].node;
var s=document.getElementById(arr[index].uniqueID);
s.innerHTML="";
if((node==null||node.selectNodes("item").length==0)&&defaultText)
{
var o=document.createElement("OPTION");
o.value=defaultValue;
o.innerText=defaultText;
s.appendChild(o);
} if(node==null)
{
if(arr[index].attach)
{
s.detachEvent("onchange",OnSelectChange);
arr[index].attach=false;
}
HandleChange(s);
return;
}
if(arr[index].attach==false)
{
s.attachEvent("onchange",OnSelectChange);
arr[index].attach=true;
}
var xns=node.selectNodes("item");
for(var i=0;i<xns.length;i++)
{
var o=document.createElement("OPTION");
o.value=EnsureString(xns.item(i).getAttribute("value"));
o.innerText=EnsureString(xns.item(i).getAttribute("text"));
s.appendChild(o);
}
var si=0;
if(index!=0)
si=EnsureInt(node.getAttribute("selectedIndex"));
if(si==0)si="0";
if(s.options.length)
s.selectedIndex=parseInt(si);
HandleChange(s);
}
}</script><BODY>
<% DbPath = SERVER.MapPath("xxx.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath
%>
<XML id=oxml>
<item>
<%
set rst=server.createobject ("adodb.recordset")
sqlt="select distinct classname,classs,classss from chanpin"
rst.open sqlt,conn,3,1
name1=""//同一個錶中的三個相關聯的字段
name2=""//同一個錶中的三個相關聯的字段
name3=""//同一個錶中的三個相關聯的字段
do while not rst.eof
If name1<>rst("classname").Value Then
If name1<>"" Then Response.Write "</item></item>"
name1=rst("classname").Value
Response.Write "<item text='"+rst("classname").Value+"' value='"+rst("classname").Value+"'>"
name2=""
End If
if name2<>rst("classs") then
If name2<>"" Then Response.Write "</item>"
name2=rst("classs").Value
Response.Write "<item text='"+rst("classs").Value+"' value='"+rst("classs").Value+"'>"
Response.Write "<item text='ggg' value='yyyy'/>"
name3=""
end if
if name3<>rst("classss") then
name3=rst("classss").Value
Response.Write "<item text='"+rst("classss").Value+"' value='"+rst("classss").Value+"'/>"
end if
rst.movenext
loop
rst.close%>
</item>
</item>
</item>
</XML><SCRIPT>
function AlertForm(f)
{
alert(
"s1:\t"+GetSelectOption(f("s1")).innerText + "\t:\t" + GetSelectOption(f("s1")).value + "\r\n"
+
"s2:\t"+GetSelectOption(f("s2")).innerText + "\t:\t" + GetSelectOption(f("s2")).value + "\r\n"
+
"s3:\t"+GetSelectOption(f("s3")).innerText + "\t:\t" + GetSelectOption(f("s3")).value + "\r\n"
);
return event.returnValue=false;
}
function GetSelectOption(s)
{
return s(s.selectedIndex);
}
</SCRIPT>
<FORM id=f1 onsubmit="AlertForm(this)"
>
<SELECT name="s1" style="width:100px;">
</SELECT>
<SELECT name="s2" style="width:100px;">
</SELECT>
<SELECT name="s3" style="width:100px;">
<!--
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//将上面的<SELECT name="s3" style="width:100px;">修改为
<SELECT name="s3" style="display:none;width:100px;" >就变成二级别的了@~@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-->
</SELECT>
<INPUT type="submit">
</FORM>
<input type=hidden id=inpSave style="behavior:url(#default#savehistory)" value="0;0;0">
</BODY><script>
var C=AttachXMLForSelect(oxml.XMLDocument,[f1("s1"),f1("s2"),f1("s3")]);
function window.onload()
{
var sis=inpSave.value;
var arr=sis.split(";");
f1("s1").selectedIndex=parseInt(arr[0]);
C.HandleChange(f1("s1"));
f1("s2").selectedIndex=parseInt(arr[1]);
C.HandleChange(f1("s2"));
f1("s3").selectedIndex=parseInt(arr[2]);
C.HandleChange(f1("s3"));
}
function window.onbeforeunload()
{
inpSave.value=""+f1("s1").selectedIndex+";"+f1("s2").selectedIndex+";"+f1("s3").selectedIndex;
}
</script>
</html>
第一个页面:
index.asp
<script language="javascript">
function loadasp(locationid){
document.frames["hiddenframe"].location.replace("loadasp.asp?xslcid="+locationid);
}
</script>
<select name=xslc onchange="javascript:loadasp(this.value);">
<option value=1>销售流程1
<option value=1>销售流程2
<option value=1>销售流程3
</select><div id=divxsjdc>
<select name=xsjd>
<option value="">请选择
</select>
</div><iframe id="hiddenframe" width="0" height="0"></iframe>
loadasp.asp
<%
有ID,你可以通过asp的数据查询形成InnerString(HTML格式了,也就是xsjd的select的HTML代码)了,明白了吗?不明白,就发短消息给我
%>
<HTML>
<BODY>
</BODY>
</HTML>
<script language="javascript">
parent.Div<%=intPCID%>.innerHTML = "<%=InnerString%>";
</script>