0

这是我的html:

<div id="TAB_CLIENTPANE" class="panel_tabs k-widget k-header k-tabstrip" style="height: 328px;" data-role="tabstrip" tabindex="0" role="tablist" aria-activedescendant="TAB_CLIENTPANE_ts_active">
    <ul class="k-tabstrip-items k-reset">
        <li class="k-item k-state-default k-tab-on-top k-state-active k-first" role="tab" aria-controls="TAB_CLIENTPANE-1" aria-selected="true">
            <span class="k-link">Summary Report</span>
            <a class="tab_win k-button"><span class="k-icon k-i-maximize"></span></a>
            <a class="tab_close k-button"><span class="k-icon k-i-close"></span></a>
        </li>
        <li class="k-item k-state-default k-last" role="tab" aria-controls="TAB_CLIENTPANE-2">
            <span class="k-link">Profit Report</span>
            <a class="tab_win k-button"><span class="k-icon k-i-maximize"></span></a>
            <a class="tab_close k-button"><span class="k-icon k-i-close"></span></a>
        </li>
    </ul>
    <div class="k-content k-state-active" style="display: block; height: 290px;" aria-expanded="true" role="tabpanel" id="TAB_CLIENTPANE-1">
        <div id="POSITIONREPORT" data-role="grid" class="k-grid k-widget k-secondary" style="height: 288px;">
            <!--lots of divs etc-->
        </div>
    </div>
    <div class="k-content" style="display: none; height: 290px;" aria-hidden="true" aria-expanded="false" role="tabpanel" id="TAB_CLIENTPANE-2">
        <div id="PROFITREPORT" data-role="grid" class="k-grid k-widget k-secondary" style="height: 288px;">
            <!--lots of divs etc-->
        </div>
    </div>
</div>

我想编写一个方法,如以下描述中所述:

function get_li(id_of_div){
    // the parameter id_of_div will be the id of divs, 
    // eg: "POSTIONREPORT", "PROFITREPORT" etc.
    // let's say the parameter passed to the function is "PROFITREPORT"
    // PROFITREPORT is the second div after the ul element, so
    // the function has to return the second li element of the ul
}

我该如何选择正确的 li?

提前致谢,

4

2 回答 2

1

这将返回您的权利li

function get_li(id_of_div){
    var index = $('#TAB_CLIENTPANE > div').index($('#' + id_of_div).parent());
    return $('#TAB_CLIENTPANE > ul > li').eq(index);
}

JSFiddle 示例 - http://jsfiddle.net/zBkyJ/

于 2013-11-01T11:57:18.030 回答
0
return $('li').eq($('.k-content').index($('#'+id_of_div).parent()));

那应该为您提供所需的元素

于 2013-11-01T11:53:05.770 回答