免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1370 | 回复: 0
打印 上一主题 下一主题

简单小巧的多级联动菜单 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-03 00:33 |只看该作者 |倒序浏览
代码
// 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
        var optionParam = response.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>', {});  


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10945/showart_332795.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP