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

复制代码 代码如下:


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 < 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'/>);
        });
 


页面代码:

复制代码 代码如下:


<tr>
                    <th>一级栏目</th>
                          <td valign="middle">
                            <s:select list="channelList" listKey="channelId"
                                listValue="channelName" 
                                key="article.subChannel.channel.channelId"
                                onchange="querySub(this.value)"></s:select>
                          </td>
                 </tr>
                 <tr>
                    <th>二级栏目</th>
                          <td valign="middle">
                          <s:select list="{}" headerKey="" headerValue="-请选择-"></s:select>
                          <!--<s:property value="article.subChannel.subName"/>
                          --></td>
                 </tr>


服务器端

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdgggx.html