javascript

位置:IT落伍者 >> javascript >> 浏览文章

AJAX实现无限级联动菜单效果


发布日期:2021年10月01日
 
AJAX实现无限级联动菜单效果

<html>

<head>

<meta httpequiv=ContentType content=text/html; charset=gb>powered by

<meta content=琥珀[hopesoft] name=author>

<title>琥珀网 无限级联动菜单[AJAX版]</title>

<style type=text/css>

body td

{

fontfamily: 宋体;

fontsize: px;

}

</style>

<script language=JavaScript>

function GetResult(strclassid)

{

/*

* GetResult(strclassid)

* GetResult(str)

* 功能:通过XMLHTTP发送请求返回结果

* 参数:str字符串发送条件;classid数字菜单级别

* 实例:GetResult(documentalluseridvalue);

* GetResult(strclassid)

*/

//定义菜单级数菜单ID数组菜单对应字段数组

var MenuIdArrMenuFieldArrMenuClass

MenuIdArr= new Array()

MenuFieldArr=new Array()

MenuClass=

MenuIdArr[]=sel

MenuIdArr[]=sel

MenuIdArr[]=sel

MenuIdArr[]=sel

MenuFieldArr[]=name

MenuFieldArr[]=name

MenuFieldArr[]=name

MenuFieldArr[]=name

if (windowXMLHttpRequest) { // Mozilla Safari

http_request = new XMLHttpRequest();

} else if (windowActiveXObject) { // IE

http_request = new ActiveXObject(MicrosoftXMLHTTP);

}

var linkurl=ajax_serverasp?classid=+classid+&sel=+str+&fieldname=+MenuFieldArr[classid+]

(GETlinkurlfalse);

(null);

//服务器端处理返回的是经过escape编码的字符串

//在页面显示服务器查询结果

var returntxt=unescape()

if(returntxtlength>)

{documentallajaxinnerHTML=服务器返回结果<font color=red>+returntxt+</font> [Powered by AJAX]}

else

{documentallajaxinnerHTML=}

//通过XMLHTTP返回数据开始构建Select

//BuildSel(returntxteval(documentall+MenuIdArr[classid+]))

BuildSel(returntxtdocumentgetElementById(MenuIdArr[classid+]))

//============更改下下级以下菜单为空==============

var kkk

for(kkk=classid+;kkk<=MenuClass;kkk++)

{

submenu=documentgetElementById(MenuIdArr[kkk])

submenulength=

submenuoptions[]selected=true

}

}

function BuildSel(strsel)

{

/*

* BuildSel(strsel)

* BuildSel(strsel)

* 功能:通过str构建Select

* 参数:str字符串由服务端返回的有特定结构字符串|字符串字符串

* 也可为字符串序号|字符串文本字符串序号|字符串文本字符串序号|字符串文本如本例

* 参数:sel要构建的Select

* 实例:BuildSel(unescape(oBaoresponseText)documentallsel)

* BuildSel(strsel)

*/

//先清空原来的数据

seloptionslength=;

var arrstr = new Array();

arrstr = strsplit();

//开始构建新的Select

seloptionsadd(new Option( 请选择));

if(strlength>)

{

for(var i=;i<arrstrlength;i++)

{

//分割字符串

var subarrstr=new Array

subarrstr=arrstr[i]split(|)

//生成下级菜单

seloptionsadd(new Option(subarrstr[]subarrstr[]));

}

seloptions[]selected=true

}

}

</script>

<form name=form method=post action=>

<table width=% border= align=center cellpadding= cellspacing= bgcolor=#CCCCCC>

<tr bgcolor=FFF>

<td height= colspan= align=center>琥珀无限级联动菜单AJAX版 [HPMenu_AJAX V]</td>

</tr>

<tr bgcolor=#FFFFFF>

<td width=% height= align=center>所 在 洲:</td>

<td><select name=sel id=sel onChange=GetResult(thisvalue)>

<option value= selected>请选择</option>

<option value=>亚洲</option>

<option value=>欧洲</option>

</select></td>

</tr>

<tr bgcolor=#FFFFFF>

<td height= align=center>国家:</td>

<td><select name=sel id=sel onChange=GetResult(thisvalue)>

<option value= selected>请选择</option>

</select></td>

</tr>

<tr bgcolor=#FFFFFF>

<td height= align=center>城市:</td>

<td><select name=sel id=sel onChange=GetResult(thisvalue)>

<option value= selected>请选择</option>

</select></td>

</tr>

<tr bgcolor=#FFFFFF>

<td height= align=center>地区:</td>

<td><select name=sel id=sel>

<option value= selected>请选择</option>

</select></td>

</tr>

<tr bgcolor=FFF>

<td height= colspan= align=center id=ajax>&nbsp;</td>

</tr>

</table>

<br>

<table width=% border= align=center cellpadding= cellspacing=>

<tr>

<td height= align=left>&nbsp;</td>

</tr>

<tr>

<td height= align=left>&nbsp;</td>

</tr>

<tr>

<td height= align=left>&nbsp;</td>

</tr>

<tr>

<td height= align=left>&nbsp;</td>

</tr>

<tr>

<td height= align=left>&nbsp;</td>

</tr>

<tr>

<td height= align=center>&nbsp;</td>

</tr>

</table>

<script language=javascript>

GetResult(documentgetElementById(sel)value)

</script>

</form>

</body>

</html>

               

上一篇:Ajax三部曲:Why not,Why,When

下一篇:JavaScript CSS Style属性对照表