簡體   English   中英

如何從刪除的可排序元素中獲取div類名稱/ ID?

[英]How to get div class name/id from dropped sortable element?

我正在對我創建的表進行排序。 我想要的是能夠獲取包含我刪除的元素的div類名稱。

這是我的html:

<div class="@c.CodigoAgrupador">
    <div class="subcatalog">
        @foreach (CodigoAgrupadorCuentas_CE c2 in Model.CodigosAgrupadores)
        {
            if (double.Parse(c2.CodigoAgrupador) > double.Parse(c.CodigoAgrupador) && double.Parse(c2.CodigoAgrupador) < (double.Parse(c.CodigoAgrupador) + 1))
            {
                <h4><a href="#">@c2.CodigoAgrupador  -  @c2.NombreCuenta</a></h4>
                <div>
                    <div class="SpecificCatalog">
                        <ol>
                            <li class="placeholder">Add your items here</li>
                        </ol>
                    </div>
                </div>
            }
        }
    </div>
    <div class="GeneralCatalog">
        <ol>
            <li class="placeholder">Add your items here</li>
        </ol>
    </div>
</div>

這是我腳本的一部分:

<script>
    $(function () {
        $("#catalog").accordion({
            collapsible: true,
            active: false,
            autoHeight: false,
            change: function (event, ui) {
                var currentHeaderID = ui.newHeader.find("a").attr("id");
                window.alert(currentHeaderID);
            }
        });
        $(".subcatalog").accordion({
            collapsible: true, active: false, autoHeight: false,
            change: function (event, ui) {
                var currentHeaderID = ui.newHeader.find("a").attr("id");
                window.alert(currentHeaderID);
            }
        });

        $(".GeneralCatalog").sortable({
            connectWith: ".SpecificCatalog, .listaCatalogosContenido", helper: "clone",
            appendTo: "body",

            stop: function (event, ui) {
                //console.log((this).sortable('toArray', { attribute: 'value' }));
                console.log(ui.item);

                //$("div#catalog h3 a").each(function (item) {
                //    alert($(this).text());
                //});
            }
        });
    });
</script>

我感興趣的是,當我從jquery調用stop函數時,可以使用ui.item來獲取包含它的div的類名,例如:

ui.item.parent.getclassname();

我不想知道元素是否在類中,我想知道類名。 抱歉,如果很難理解,我的英語不是最好的。 歡迎任何幫助。

您應該能夠執行以下操作:

ui.item.parent().hasClass(<whatever you want to test>)

請說明是否沒有給您想要的東西...

好的,只要重新閱讀您的問題,聽起來就好像您想了解父div所有類,而不僅僅是div具有特定的類。 從另一個SO問題/答案中 ,您可以執行以下操作:

ui.item.parents('div')[0].className.split(/\s+/);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM