晕啊,完整的,怕你没时间看啊
第一次玩这个AJAX,所以有点乱,特别是改来改去地,自己都乱了.
<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
<!--
-->
</style>
</head>
<%
const MaxPerPage=18
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
dim sql
dim rs
dim rstype
dim typesql
dim typeid,typename1
if not isEmpty(request("typeid")) then
typeid=request("typeid")
else
typeid=1
end if
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
%>
<script language="JavaScript">
var mrow,nn1,zk,n3,nn2,zk2,mrow2,n4
zk=0;
zk2=0;
nn1=0;
nn2=0;
n3=0;
n4=0;
mrow=0;
mrow2=0;
var http_request=false;
function send_request(url){
http_request=false;
if (window.XMLHttpRequest){
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){
http_request.overrideMimeType("text/xml");
}
}else if(window.ActiveXObject){
try{
http_request=new ActiveXObject("Microsoft.XMlHTTP");
}catch(e){
}
}
if (!http_request){
window.alert("不能创建XMLHttpRequest对象实例!");
return false;
}
http_request.onreadystatechange=processRequest;
http_request.open("GET",url,true);
http_request.send(null);
}
function processRequest(){
if(http_request.readystate==4){
if (http_request.status==200){
if (http_request.responseText!=""){ //有请求内容
abc = http_request.responseText.split("!"); //把请求内容送到abc
if (nn2==0 ){ //如果是第一级运行以下
n3=abc[0] //这是返回的个数
if (zk==1){ //如果已经展开先合上
for (n=1;n<n3-0+1;n++){
cd.deleteRow(mrow-0);
}
nn1=0;
zk=0
}else{ //这儿开始展开
for (n=1;n<n3-0+1;n++){
bbb=abc[n].split(",");
row=cd.insertRow(mrow-0);
cell=row.insertCell(0);
cell.align="left";
urrl="kjfg.asp?newstype="+bbb[0]+"&typeid="+bbb[2]+"&n=1"
if (bbb[1]>0){//返回有下一级菜单的话
cell.innerHTML="<div align='left' style='padding-left:10px;padding-right:6px;' id=div"+n+"><img src='../image/plus.gif' onclick=extendType2("+n+","+bbb[2]+") style='cursor:hand' id='TypeImg"+bbb[2]+"'><a class='d' href='"+urrl+"' onclick='return move();'> "+bbb[0]+"</a></div>";//这儿生成的是第二级菜单的主体,也就是那个document.getElementById(tdid).
}else{//无下一级菜单的话
cell.innerHTML="<div align='left' style='padding-left:10px;padding-right:6px;'><img src='../image/nochild.gif'><a class='d' href='"+urrl+"' onclick='return move();'> "+bbb[0]+"</a></div>";
}
}
zk=1
}
}else{ //这是第二级展开
n4=abc[0] //这是返回的个数
if (mmm) {
for (n=1;n<n4-0+1;n++){//说明一下,减0只是为了转换一下n4的属性.因为它是字符,减0就成了数字了.不减0如果n4为1它会成为11的
divid="td"+mrow2
del=document.getElementById(divid).removeNode(true)
}
imgid="TypeImg"+nn2
//alert(imgid)
document.getElementById(imgid).src = '../image/plus.gif'; //更改图标
mmm=false
nn2=0
}else{
imgid="TypeImg"+nn2
//alert(imgid)
document.getElementById(imgid).src = '../image/nochild.gif'; //更改图标
for (n=1;n<n4-0+1;n++){
tdid="div"+mrow2
bbb=abc[n].split(",");
divid="td"+mrow2
urrl="kjfg.asp?newstype="+bbb[0]+"&typeid="+bbb[2]+"&n=1"
//alert(urrl)
document.getElementById(tdid).innerHTML+="<div align='left' style='padding-left:10px;padding-right:6px;'><img src='../image/nochild.gif'><a class='d' href='"+urrl+"' onclick='return move();' id="+divid+"> "+bbb[0]+"</a></div>"; //这儿展开的是第二级的菜单,可以很好地展开,并且联接正解,只要把move中的return false去了就能转到这个联接中.
}
zk2=1
}}
}else{
alert("无此ID号!");
}
}else{
alert("您所请求的页面有异常!");
}
}
}
function extendType2(mm,nn) {//这第二级菜单的点击
imgid="TypeImg"+nn2
mrow2=mm //获取行号
nn2=nn //获取ID号
imgid="TypeImg"+nn2
j=document.getElementById(imgid).src.indexOf("plus.gif")
if(j>0){
mmm=false
send_request('extend1.asp?id='+nn) //送出请求
}else{
mmm=true
send_request('extend1.asp?id='+nn) //送出请求
}
}
function extendType1(mm,nn) {//第一级菜单的点击
nn2=0
if (nn1!=nn){ //该次点击是否与上次相同,不同运行下面的
if (nn1!=0){ //如果第一级已展开,那就先合上(为的是表格的序号不会)
imgid="TypeImg"+nn1 //获取前缀图标位置
document.getElementById(imgid).src = '../image/plus.gif'; //改变图标
for (n=1;n<n3-0+1;n++){ //循环删除添加的行
cd.deleteRow(mrow-0);
}
nn1=0;
zk=0
}
nn1=nn //项目标号
mrow=mm //表格行号
imgid="TypeImg"+nn //当然前缀图标位置
document.getElementById(imgid).src = '../image/nochild.gif'; //更改图标
send_request('extend1.asp?id='+nn) //送出请求
}else{ //相同只运行以下的删除
if (nn1!=0){
imgid="TypeImg"+nn1
document.getElementById(imgid).src = '../image/plus.gif';
for (n=1;n<n3-0+1;n++){
cd.deleteRow(mrow-0);
}
nn1=0;
zk=0
}
}
}
function move() {
alert(event.srcElement.name)//这儿如果是第二级菜单无法返回内容,第一级没问题
zhengshi2_obj0.location=event.srcElement.href //先偷懒,把它送到IFRAME,看以后再换
return false
}
</script>
<body leftmargin="2" topmargin="2">
<div align="center" class="unnamed1">
<center>
<div align="center">
<center>
<table width="774" border="0" cellpadding="0" cellspacing="0" height="9" style="border-collapse: collapse" bordercolor="#111111">
<tr>
</tr>
</table>
</center>
</div>
<div align="center">
<center>
<!--#include file="bt.asp"-->
</div>
<div id=d5 align="center" >
<table width="774" border="0" cellpadding="0" cellspacing="0" height="1" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td bgcolor="#7D8AC8" width="129" height="143" valign="top">
<div align="center">
<center>
<table width="140" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" height="91">
<tr>
<td colspan="2" height="28" width="139">
<p align=center><font face="宋体" style="font-size: 10pt" color="#FFFF00"><a href=mymanage.asp>税法栏目</a> <a href=mymanage2.asp>会计法栏目</a></font></td>
</tr>
<tr>
<td colspan="2" height="2" width="139"></td>
</tr>
<tr>
<td height="61" width="130" valign="top">
<table width="137" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" height="58" width="100%">
<table width=100% border="0" cellpadding="0" cellspacing="0" height="1" style="border-collapse: collapse" id="cd">
<%
Set rst= Server.CreateObject("ADODB.Recordset")
rst.open "select * from type2 where class=0",conn,1
if rst.EOF then
response.write "没有栏目:("
else
%> <%for n=1 to rst.recordcount%>
<tr><td><img src="../image/plus.gif" onclick="extendType1('<%=n%>','<%=rst("typeid")%>')" style="cursor:hand" id="TypeImg<%=rst("typeid")%>"><a class="d" href="kjfg.asp?newstype=<%=rst("type")%>&typeid=<%=rst("typeid")%>&n=1" onclick="return move();"><%=rst("type")%></a></td></tr>
<%
rst.MoveNext
next
end if
rst.close
%></table> </td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</div>
<table width="75%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
</tr>
</table>
</td>
<td bgcolor="#C4C4C4" width="1" height="143"></td>
<td colspan="2" height="143" valign="top" align="right" width="608">
<IFRAME id=zhengshi2_obj0
src="kjfg.asp?newstype=会计法规&typeid=0&n=1" frameBorder=0 width=100%
height=100%></IFRAME>
</td>
</tr>
</table>
</center>
</div>
<div align="center">
<center>
<table width="774" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr bgcolor="#304D7C">
<td width="777" bgcolor="#000080" class="unnamed1" height="1">
<div align="center"> </div>
</td>
<td width="1" valign="top" align="right" height="2"></td>
</tr>
</table>
</center>
</div>
<script language="Javascript" src="copyright.txt">
</script>
</center></div>
</body>
</html>
[此贴子已经被作者于2007-11-21 9:50:22编辑过]