欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用jquery生成二級(jí)菜單的實(shí)例代碼

 更新時(shí)間:2013年06月24日 11:04:51   作者:  
這篇文章介紹了用jquery生成二級(jí)菜單的代碼,需要的朋友可以參考一下

javascript

頁面中的函數(shù)

復(fù)制代碼 代碼如下:

function querySub(id,sid/*選中的項(xiàng)*/){
$.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 < jsonObj.length; i++) {
                        var $option = $('<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(<s:property value='article.subChannel.channel.channelId'/>,<s:property value='article.subChannel.subId'/>);
        });
 

頁面代碼:
復(fù)制代碼 代碼如下:

<tr>
                    <th>一級(jí)欄目</th>
                          <td valign="middle">
                            <s:select id='_channel' list="channelList" listKey="channelId"
                                listValue="channelName" 
                                key="article.subChannel.channel.channelId"
                                onchange="querySub(this.value)"></s:select>
                          </td>
                 </tr>
                 <tr>
                    <th>二級(jí)欄目</th>
                          <td valign="middle">
                          <s:select name='article.subChannel.subId' list="{}" headerKey="" headerValue="-請選擇-"></s:select>
                          <!--<s:property value="article.subChannel.subName"/>
                          --></td>
                 </tr>

服務(wù)器端

復(fù)制代碼 代碼如下:

 public String querySubChannelArticle(){ 
        HttpServletResponse response=getResponse();
        HttpServletRequest request=getRequest();
        response.setContentType("application/json; charset=UTF-8");
        PrintWriter out =null;
        try {
            out = response.getWriter();

            List<Map<String,Object>> list = new LinkedList<Map<String,Object>>();
            if(channelId!=null && !channelId.equals("")){
                Channel tmp = new Channel();
                tmp.setChannelId(Integer.parseInt(channelId));
                subChannelList = subChannelDAO.listSubChannel(tmp);

                for(Object oo:subChannelList){
                    Map<String,Object> obj = new HashMap<String,Object>();
                    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;
    }  

其實(shí)蠻簡潔的

相關(guān)文章

最新評(píng)論