看到今天贴了几个联动菜单的帖子
这个应该大家都有各自比较好的代码了
我也顺手贴一个我们team里面用的比较小巧的代码
// author: downpour
var DoubleCombo = Class.create();
DoubleCombo.prototype = {
initialize: function(source, target, ignore, url, options, excute) {
this.source = $(source);
this.target = $(target);
this.ignore = $A(ignore);
this.url = url;
this.options = $H(options);
this.source.onchange = this.doChange.bindAsEventListener(this);
if(excute) {
this.doChange();
}
},
doChange: function() {
if(this.source.value != '') {
// first clear the ignore ones
this.ignore.each(
function(value) {
$(value).options.length = 1;
$(value).options[0].selected = 'selected';
}
);
// create parameter for ajax
var query = $H({ id: this.source.value });
var parameters = {
method: 'post',
parameters: $H(this.options).merge(query).toQueryString(),
onComplete: this.getResponse.bindAsEventListener(this)
}
var locationRequest = new Ajax.Request( this.url, parameters );
}
},
getResponse: function(request) {
this.target.options.length = 1;
this.target.options[0].selected = 'selected';
var response = $A(request.responseText.trim().split(';'));
response.length--;
for(var i = 0; i < response.length; i++) {
var optionParam = response[i].split(',');
this.target.options[this.target.options.length] = new Option(optionParam[1], optionParam[0]);
}
}
}
简单说一下几个参数吧:
source 第一级菜单
target 联动菜单
ignore 当有时候3级联动时,例如 国家 省 市 例如上海没有省的,可以忽略第3级菜单
url action url
options action参数
excute 是否联动
拿比较常见的例子来看 国家 省 市 3级联动来作为例子
<html-el:select property="country" styleId="country" >
<html-el:options collection="countries" property="id" labelProperty="name" />
</html-el:select>
<html-el:select property="province" styleId="province">
<option value="">--Please Select--</option>
................
</html-el:select>
<html-el:select property="city" styleId="city">
<option value="">--Please Select--</option>
................
</html-el:select>
<script type="text/javascript">
new DoubleCombo('country', 'province', null, '<c:url value="/xxxx.do?combo=true"></c:url>', {});
<script type="text/javascript">
new DoubleCombo('province', 'city', null, '<c:url value="/xxxx.do?combo=true"></c:url>', {});
分享到:
相关推荐
ajax+jsp实现的多级联动菜单的实现。
ajax+json实现多级联动菜单.doc
多级联动菜单 div+css +js
使用jquery实现多级菜单的联动,实现菜单导航链接。
这是一个多级联运菜单自动生成程序,很好用的只要你输入你想要的几级数就可以自动生成了
一款多级菜单联动的asp代码,包括三级、四级、多级等,比较好用,值得下载学习
jQuery 多级 菜单,代码清晰,容易修改
jQuery多级联动菜单选中代码是一款jQuery基于tnTreeBox.js插件制作的三级联动菜单点击一级单选二级三级多选选中取消,支持清空和删除效果代码。
JavaScript 自定义多级联动下拉菜单
as3做的多级联动菜单,全部的工程文件,包括贴图都在,希望和各位共同学习
JavaScript 自定义多级联动浮动菜单!JavaScript 自定义多级联动浮动菜单!JavaScript 自定义多级联动浮动菜单!JavaScript 自定义多级联动浮动菜单!源码下载!
VBA设置多级下拉菜单.xlsm VBA设置动态多级下拉菜单.xlsm
用prototype实现的简单小巧的多级联动菜单
js控制全国省市县无刷新多级联动菜单、下载后打开即可使用
多款多级联动下拉菜单打包!必有一款适合你!ajax,php,js,等!
多级联动下拉菜单,可单选可多选,使用了jQuery.Hz2Py,支持中英文混合检索
中国省市县多级联动菜单省份城市县区三级级联菜单,主要使用JAVASCRIPT编写,方便使用,其中在后台调用前台的菜单内容时,可以用Request["ID"] 来获取前台的值。
本文介绍了Excel内如何设置多级联动下拉菜单,即选择一个数据后,后续数据根据前一个数据的选择结果进行过滤。
Jquery简单的多级联动: 1、下拉框对应的文本框 2、下拉框对应的下拉框