一拖三下拉菜单(js+xml+asp)
发表于:2007-06-30来源:作者:点击数:
标签:
script var m_oXMLDoc = new ActiveXObject(Microsoft.XMLDOM); //--------------cid为父级ID var m_sBaseSrc = Tree.asp?cid=; //---------------id 为所属类型----- var m_sBaseSrc1 = id=; var m_post=3; function BindSelect( strXMLSrc , objSelectName,
<script>
var m_oXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
//--------------cid为父级ID
var m_sBaseSrc = "Tree.asp?cid=";
//---------------id 为所属类型-----
var m_sBaseSrc1 = "&id=";
var m_post=3;
function BindSelect( strXMLSrc , objSelectName, defaultVal)
{
m_oXMLDoc.async = true;
m_oXMLDoc.onreadystatechange = Function( "fnLoadComplete(‘’" + objSelectName + "‘’, ‘’" + defaultVal + "‘’);" );
if (objSelectName=="jz_3"){ strXMLSrc=strXMLSrc+m_sBaseSrc1+0;}
if (objSelectName=="jz_25"){ strXMLSrc=strXMLSrc+m_sBaseSrc1+1;m_post=2;}
if (objSelectName=="jz_9"){ strXMLSrc=strXMLSrc+m_sBaseSrc1+2;}
if (objSelectName=="jz_10"){ strXMLSrc=strXMLSrc+m_sBaseSrc1+3;}
m_oXMLDoc.load( strXMLSrc );
}
function fnLoadComplete(objSelectName, defaultVal)
{
var objSelect = document.all[objSelectName];
var aryXMLNodes;
var node;
if (objSelect == null)
return;
try
{
var iReadyState = m_oXMLDoc.readyState;
}
catch(e)
{
return;
}
if( iReadyState != 4 ) return;
if( m_oXMLDoc != null && m_oXMLDoc.xml != "" )
{
objSelect.length = 0;
aryXMLNodes = m_oXMLDoc.documentElement.selectNodes("Tree_0");
objSelect.options[0] = new Option("==请选择==");
for (var i=0; i < aryXMLNodes.length; i++)
{
node = aryXMLNodes[i];
objSelect.options[i+1] = new Option(node.getAttribute("Title"),node.getAttribute("cId"));
//-------------------请注意这里,初始选择
if (node.getAttribute("cId")==1||node.getAttribute("cId")==2||node.getAttribute("cId")==3||node.getAttribute("cId")==4)
{
objSelect.options[i+1].selected=true
}
}
if (defaultVal != null && defaultVal != "" && objSelect.length > 1)
{
SetSelectedValue(objSelect, defaultVal)
}
if(objSelect.ChildSelectName != null&&m_post>0)
{
m_post=m_post-1;
objSelect.onchange = Function( "var val = document.all.jz_3.value;BindSelect(m_sBaseSrc+val, ‘’"+objSelect.ChildSelectName+"‘’, ‘’"+defaultVal+"‘’);if(val!=‘’‘’)document.all.MaterialClassCode.value=m_post;" );
objSelect.fireEvent("onchange");
}
else
{
objSelect.onchange = Function( "var val = document.all.jz_3.value;if(val!=‘’‘’)document.all.MaterialClassCode.value=m_post;" );
}
}
}
function InitSelect(defaultVal)
{
//document.all.MaterialClassCode.value = "";
BindSelect( m_sBaseSrc + "0", "jz_3", defaultVal);
//document.write( m_sBaseSrc + "0"+"&cid="+0, "jz_3", defaultVal);
//BindSelect( m_sBaseSrc + "1", "jz_9", defaultVal);
}
function Equality(val1,val2)
{
if (val1.length < val2.length || val2 == "")
return false;
return (val1.substr(0,val2.length) == val2)
}
function SetSelectedValue(oSel,val)
{
if (val == null)
return;
for(var i=0; i<oSel.length; i++)
{
if (Equality(val, oSel.options[i].value))
{
oSel.selectedIndex = i;
if(oSel.ChildSelectName == null)
oSel.fireEvent("onchange");
break;
}
}
}
window.onload = function(){InitSelect();}
</script>
//------------------------------------tree.asp---------
<!--#include file="../inc/asp/all.asp"-->
<%
tree=3
Dim xmlDoc, tmp(3), root,rows_A(1),i,newElem
‘’Dim root As IXMLDOMElement
‘’Dim newElem As IXMLDOMElement
response.ContentType = "text/xml" ‘’输出格式为xml
tmp(0) = Request("cid")
tmp(1) = Request("id")
If tmp(0) =empty or tmp(1) =empty Then
Response.Write "<Tree/>"
Response.End
End If
set xmlDoc=server.CreateObject("Microsoft.XMLDOM") ‘’新建xmldom对象
xmlDoc.loadXML("<Tree cId="""&tmp(0)&""" Src=""Tree.asp?cid="&tmp(0)&"""/>")
set root = xmlDoc.documentElement
‘’----------请注意,这里是用的我定义的类,打开的
数据库
call jz.conn_00(0,tree)
call jz.c_r_s(0,true,true)
jz.
sql(0)="select jz_0,jz_1,jz_2,jz_4 from Jz_Template where jz_2="&tmp(0)&" and jz_4="&tmp(1)
call jz.c_r_o(0,0,1)
If not jz.rs(0).eof Then
rows_A(1)=jz.rs(0).GetRows
rows_A(0)=ubound(rows_A(1),2)
for i=0 to rows_A(0)
Set newElem = xmlDoc.createElement("Tree_0")
root.appendChild newElem
newElem.setAttribute "cId",rows_A(1)(0,i)
newElem.setAttribute "Title", rows_A(1)(1,i)
next
end if
call jz.c_r_e(0,tree,tree)
Response.Write "<?xml version=""1.0"" encoding=""gb2312""?>"&xmlDoc.xml
%>
原文转自:http://www.ltesting.net