从材料可折叠中获取活动索引

时间:2017-11-10 08:31:53

标签: javascript html material-design material-ui material

我想获得一个materialcss崩溃中活跃的索引。

我尝试使用以下代码



function getActive() { return($('.active').data("index")) } $(document).ready(function(){ $('.collapsible').collapsible(); });

<!-- Compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
    
    <!-- Compiled and minified JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
    
    <ul class="collapsible" data-collapsible="accordion">
        <li>
            <div class="collapsible-header"><i class="material-icons">filter_drama</i>First</div>
            <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
        </li>
        <li>
            <div class="collapsible-header"><i class="material-icons">place</i>Second</div>
            <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
        </li>
        <li>
            <div class="collapsible-header"><i class="material-icons">whatshot</i>Third</div>
            <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
        </li>
    </ul>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您想使用.index()功能:

function getActive() { return $('.active').index(); }