完成折叠后,如何获取href值?

时间:2019-03-28 20:22:33

标签: javascript

我想在“手风琴”切换或折叠过程中获取href值。

<div class="row">
    <div class="col-md-12">
        <div class="portlet">
            <div class="portlet-heading bg-inverse">
                <h3 class="portlet-title">acilsusam 1</h3>
                <div class="portlet-widgets">
                    <a data-toggle="collapse" data-parent="#value1" href="#birinci"><i class="ion-minus-round"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="birinci" class="panel-collapse collapse show" style="">
                <div class="portlet-body">
                    <div class="row">
                        <div class="col-xl-3">
                            <a href="cizmelikedi.php?id=1">
                                <div class="widget-bg-color-icon card-box p-l-0 m-b-0">
                                    <div class="bg-icon pull-left m-r-10">
                                        <i class="md  md-mail text-danger" style="font-size: 60px !important;"></i>
                                    </div>
                                    <div class="text-left m-t-15">
                                        <p class="text-muted">sunucu nunu 1</p>
                                    </div>
                                    <div class="clearfix"></div>
                                </div>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <div class="portlet">
            <div class="portlet-heading bg-inverse">
                <h3 class="portlet-title">acilsusam 2</h3>
                <div class="portlet-widgets">
                    <a data-toggle="collapse" data-parent="#value" href="#ikinci"><i class="ion-minus-round"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="ikinci" class="panel-collapse collapse show" style="">
                <div class="portlet-body">
                    <div class="row">
                        <div class="col-xl-3">
                            <a href="cizmelikedi.php?id=1">
                                <div class="widget-bg-color-icon card-box p-l-0 m-b-0">
                                    <div class="bg-icon pull-left m-r-10">
                                        <i class="md  md-mail text-danger" style="font-size: 60px !important;"></i>
                                    </div>
                                    <div class="text-left m-t-15">
                                        <p class="text-muted">sunu bunu yap</p>
                                    </div>
                                    <div class="clearfix"></div>
                                </div>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

我尝试了很多事情,但是在某种程度上href =“#birinci”并没有获得价值。

$('.collapse').on('hidden.bs.collapse', function () {                           
   var sectionID = $('.collapse').closest('a').attr('href');                                    
   $.ajax({                                     type: "POST",                                       
     data: "collapse_islemi=1&islem=e&collapse="+sectionID,                                     
     url: "https://localhost/ajax.php",                                     
     success: function(html) {}                                 
   });
});

当我想要在更改时获取价值时,我尝试了很多方法。我尝试使用find attr,但每次都会收到未定义的警告。

1 个答案:

答案 0 :(得分:1)

$('.collapse').on('hidden.bs.collapse', function () {        
    alert(e.currentTarget.id);
});

我得到了上面的值。