andsky
(andsky)
注册会员

一般会员
UID 63241
精华
0
积分 77
帖子 82
金钱 77 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2005-2-18
状态 离线
|
[广告]: Enom域名自助付费 自助注册 自助PUSH 主流域名COM等一律57.99元年
贴一个ajax 的联动菜单
这个主要是为了选择城市而写的
<?php /** [email]andsky888@gmail.com[/email] citys, 联动菜单 选定值,表单名,选择框名,连动清空如每三个 citys.init(value,form,select,clean); **/
var citys = { value: 0, form: null, select: null, url: "index.php?module=ajax&action=province&cid=", init: function (value,form,select,clean) { //alert(value); this.value = value; this.form = document.forms[form]; this.select = select; //alert(clean); if (typeof clean != 'undefined') { this.Clean(clean); this.Default(clean); } //alert(value); if (value == -1) return; this.GetData();
},
GetData: function() { var req = new Request( function() { if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200) { //alert(req.xmlhttp.responseText); citys.SetData(req.xmlhttp.responseText); } } ); req.get(this.url+this.value);
},
SetData: function(data) { var rxr = data.trim().split(","); this.Clean(this.select); this.Default(this.select); //alert(rxr.length); if (rxr.length > 1) { for (var i=0;i<rxr.length ; i++) { //alert(rxr[i]); var oOption = document.createElement("option"); txt = rxr[i].split("|") oOption.text = txt[1]; oOption.value = txt[0]; //document.all(this.select).options.add //select.options.add(oOption); this.form[this.select].options.add(oOption); } }
},
Clean: function(id) { this.form[id].options.length=0;
},
Default: function(id) { this.form[id].options.add(new Option('----','-1')); }
} ?>
|
|