您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

用jquery生成二级菜单的实例代码_jquery

2024/3/24 16:37:41发布18次查看
javascript
页面中的函数
复制代码 代码如下:
function querysub(id,sid/*选中的项*/){
$.post('${path}/page/article/querysubchannelarticle.action',
                {'channelid':id},function(data){
                    $('select[name=article.subchannel.subid] option[value!=]').remove();
                    var jsonobj = data;   
                    for ( var i = 0; i                         var $option = $('');
                        $option.attr('value',jsonobj[i].subid);
                        if(jsonobj[i].subid === sid){
                            $option.attr('selected',true);
                        }
                        $option.text(jsonobj[i].subname);
                        $('select[name=article.subchannel.subid]').append($option);
                    }
                });
        }
$(function(){
            querysub(,);
        });
页面代码:
复制代码 代码如下:
一级栏目
listvalue=channelname 
                                key=article.subchannel.channel.channelid
                                onchange=querysub(this.value)>
二级栏目
服务器端
复制代码 代码如下:
public string querysubchannelarticle(){ 
        httpservletresponse response=getresponse();
        httpservletrequest request=getrequest();
        response.setcontenttype(application/json; charset=utf-8);
        printwriter out =null;
        try {
            out = response.getwriter();
list> list = new linkedlist>();
            if(channelid!=null && !channelid.equals()){
                channel tmp = new channel();
                tmp.setchannelid(integer.parseint(channelid));
                subchannellist = subchanneldao.listsubchannel(tmp);
for(object oo:subchannellist){
                    map obj = new hashmap();
                    subchannel c = (subchannel)oo;
                    obj.put(subid, c.getsubid());
                    obj.put(subname, c.getsubname());
                    list.add(obj);
                }
            }
            string outstr = jsonutil.tojsonstr(list);
            out.println(outstr);
        }catch(exception e){
        e.printstacktrace();
        }
        out.flush();
        out.close();
        return null;
    }
其实蛮简洁的
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product