jQuery添加文本之间的href标签的td

jQuery add text between a href tags of td

本文关键字:href td 标签 之间 添加 文本 jQuery      更新时间:2023-09-26

我有一个链接表,这些链接可以从表中删除,我可以将表行拖放到另一个div中。一旦拖到div中,我禁用表行,因此它不能再次拖动,我还删除了允许从表中删除行的链接。

这一切都很好。一旦在被删除的div中,我添加了一个链接(字体很棒的X图标),它允许从被删除的区域中删除项/行。

因此,当在被拖放区域中单击delete链接时,该行将被删除,并且主表中对应的行将启用再次拖放。

这一切都很好。唯一不能工作的部分是将链接添加回表中的行。当我最初从主表中拖动行时,字体awesome图标(fa-times)从表行中删除,然后当从被删除的区域中删除行时,我尝试将图标添加回主表行,但没有效果。

<div class="table-responsive">
    <table class="table table-striped">
        <thead>
            <tr class="bb">
                <th class="artcl_hdr text-center"></th>
                <th class="artcl_hdr text-center">Source</th>
                <th class="artcl_hdr text-center">Title</th>
                <th class="artcl_hdr text-center">Publish Date</th>
                <th class="artcl_hdr text-center">Share</th>
            </tr>
        </thead>
        <tbody>
            <?php
            if(is_array($bookmarks))
            {
                    echo '<tr class="bmkitem" id="'.$bookmark['aid'].'">';
                    echo '<td class="text-center bkgcol-white"><a href="#" title="Delete bookmark" id="bkm_delete"><i class="fa fa-times fa-lg pomegranate" aria-hidden="true"></i></a></td>';
                    echo '<td class="text-center"><span id="article_source" class="label '.$label.'">'.$bookmark['name'].'</span></td>';
                    echo '<td class="bkm-title text-left"><a href="'.$bookmark['link'].'" target="_blank" id="bookmark-link">'.$bookmark['title'].'</a></td>';
                    echo '<td class="key-title text-center">'.$formatted_date.'</td>';
                    echo '<td class="artcl_info text-left"><div class="add-this addthis_native_toolbox" data-url="'.$bookmark['link'].'" data-title="'.$bookmark['title'].'"></div></td>';
                    echo '</tr>';
                }
            }
            ?>
        </tbody>
    </table>
</div>
</div>
<div class="panel-body text-left" id="bkm-dropbox">
    <div class="text-center">
        <p class="temp-text">Drag Bookmarks Here</p>
    </div>
</div>
jQuery

$(document).ready(function() {
    $(".bmkitem").draggable({
        helper: "clone",
        containment: "document",
        cursor: 'move',
        revert: 'true',
        start: function(event, ui) {
            source = $(this).find('#article_source').text()
            contents = $(this).find('#bookmark-link').text();
        }
    });
    $('#bkm-dropbox').droppable({
        hoverClass: 'hover',
        acceptable: '.bmkitem',
        containment: 'document',
        out: function (event, ui) {
            var self = ui;
            ui.helper.off('mouseup').on('mouseup', function () {
                $(this).remove();
                self.draggable.remove();
            });
        },
        drop: function(event, ui) {
            $(this).find(".temp-text").remove();
            $(this).append('<span><a href="Javascript:void(0)"" id="drop_delete"><i class="fa fa-times fa-lg pomegranate left_pad_push" aria-hidden="true"></i></a>' + source + ' - ' + contents + '</span><br />');
            ui.draggable.draggable("disable");
            ui.draggable.find("i").remove();
            $('#drop_delete').on('click', function () {
                $(this).parent('span').remove();
                ui.draggable.draggable("enable");
                ui.draggable.find("td#bmk_delete").text('<i class="fa fa-times fa-lg pomegranate" aria-hidden="true"></i>');
            });
        }
    });
});

使用show hide部分解析。谢谢MelanciaUK。

适用于一个项目,但不适用于从删除区域中删除其他项目。只有第一个拖拽的项目从拖放区域中删除,当单击另一个项目上的删除时,什么也不会发生。同时,拖放区域为被拖放的项目保留了一个位置/占位符,所以当我在拖放区域中拖动一个新项目时,它会被放置在上一个项目的下方。

$(document).ready(function() {
    $(".bmkitem").draggable({
        helper: "clone",
        containment: "document",
        cursor: 'move',
        revert: 'true',
        start: function(event, ui) {
            source = $(this).find('#article_source').text()
            contents = $(this).find('#bookmark-link').text();
        }
    });
    $('#bkm-dropbox').droppable({
        hoverClass: 'hover',
        acceptable: '.bmkitem',
        containment: 'document',
        drop: function(event, ui) {
            $(this).find(".temp-text").remove();
            $(this).append('<span><a href="Javascript:void(0)"" id="drop_delete"><i class="fa fa-times fa-lg pomegranate left_pad_push" aria-hidden="true"></i></a>' + source + ' - ' + contents + '</span><br />');
            ui.draggable.draggable("disable");
            selected_row = ui.draggable.find("i").hide();
            $('#drop_delete').on('click', function () {
                $(this).parent('span').remove();
                ui.draggable.draggable("enable");
                selected_row.show();
            });
        }
    });
});