javascriptjquery-easyui

When I include the accordion, I find it always defaults to the first panel


<%@include file="mainNavigation.jsp"%>

I don't like to copy the same code so I include the accordion, but when I open a new web, the accordion still at default panel. I try to write js to change the default panel, but it did not work.

${page} is the session to record it should be which panel.

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script>
    window.onload=function () {
        var a=${page};
        if(a==2){
            $("#accordion").accordion("select","账户管理");
        }
    }
</script>
<div region="west" style="width: 200px" title="功能菜单" split="true">
    <div id="accordion" class="easyui-accordion" data-options="fit:true,border:false">
        <div id="accordion_1" title="账户管理" data-options="iconCls:'icon-ok'" style="padding: 10px">
            <a href="/web/userInfo" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" style="width: 150px">个人信息</a>
            <a href="/web/resetPassword" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" style="width: 150px">密码重置</a>
        </div>

        <div id="accordion_2" title="本地文件管理" data-options="iconCls:'icon-mini-add'"  style="padding: 10px">
            <a href="/web/fileSearch" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" style="width: 150px;">文件搜索</a>
            <a href="/web/fileClassification" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'" style="width: 150px;">文件分类</a>
        </div>

        <div id="accordion_3" title="云端文件管理" data-options="iconCls:'icon-tip'"  style="padding: 10px">
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-tip'" style="width: 150px;">云端文件</a>
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-tip'" style="width: 150px;">云端上传</a>
        </div>
    </div>
</div>

Solution

  • I'm not sure why your code didn't work, but you can solve this problem by putting a tag.

    <div title="账户管理" data-options="iconCls:'icon-help'" style="padding:10px;" selected>   
    

    Also, there is nothing wrong with your code.

    $("#accordion-id").accordion("select", "title or index");
    

    link