【问题标题】:Conditional Delete of TD Element with JQuery使用 JQuery 条件删除 TD 元素
【发布时间】:2016-10-24 22:07:23
【问题描述】:

我是 Ajax 和 Stack Overflow 的新手(即使我阅读了很多线程)。 我需要删除表中的一个元素 (class="rsWrap rsLastSpacingWrapper">),以防有多个元素具有相同的 <td> 标签。

<table class="rsTimelineTable" cellspacing="0" cellpadding="0" border="0" style="border-right:0px none;">
    <tbody>
        <tr class="rsAllDayRow">
            <td class="rsAllDayCell">
                <div class="rsWrap rsLastSpacingWrapper"> </div>  <!--DO NOT DELETE -->
            </td>
            <td class="rsAllDayCell">
                <div class="rsWrap rsLastSpacingWrapper"> </div> <!--DO NOT DELETE -->
            </td>
            <td class="rsAllDayCell">
                <div class="rsWrap" style="z-index:7;">
                <div id="ctl00_M_RadScheduler1_82_0" class="rsApt rsFlownDay" style="height:100%;width:100%;" title="17.10"></div>
                <div class="rsWrap rsLastSpacingWrapper"> </div> <!TO  DELETE -->
            </td>
            <!-- Other TD tag>
    </tbody>
</table>

<table class="rsTimelineTable" cellspacing="0" cellpadding="0" border="0" style="border-right:0px none;">
    <tbody>
        <tr class="rsAllDayRow">
            <td class="rsAllDayCell">
                <div class="rsWrap rsLastSpacingWrapper"> </div> <!--DO NOT DELETE -->
            </td>
            <td class="rsAllDayCell">
                <div class="rsWrap rsLastSpacingWrapper"> </div> <!--DO NOT DELETE -->
            </td>
            <td class="rsAllDayCell">
                <div class="rsWrap" style="z-index:7;">
                <div id="ctl00_M_RadScheduler1_82_0" class="rsApt rsFlownDay" style="height:100%;width:100%;" title="17.10"></div>
                <div class="rsWrap rsLastSpacingWrapper"> </div> <!-- TO DELETE -->
            </td>
            <!-- Other TD tag>
    </tbody>
</table>
<table class="rsTimelineTable" cellspacing="0" cellpadding="0" border="0" style="border-right:0px none;">
    <!-- etc etc -->
</table>

有什么想法吗?

【问题讨论】:

  • 您的问题不清楚,您是要删除重复项还是仅删除包含具有这些类的元素的最后一个 tds。

标签: jquery html-table


【解决方案1】:

要使用 rsWrap rsLastspacingWrapper 类删除最后一个元素,您可以这样做。

$(".rsWrap, .rsLastSpacingWrapper").last().remove();

要从每个表中删除它,您可以尝试(未经测试):

$('table').each(function(){
    $(".rsWrap, .rsLastSpacingWrapper").last().remove();
});

不太确定我的语法有多正确,但它至少应该让您知道从哪里开始。

【讨论】:

    猜你喜欢
    • 2014-01-05
    • 2013-10-10
    • 2015-07-08
    • 1970-01-01
    • 2012-12-24
    • 2023-03-29
    • 2013-07-18
    • 2010-11-01
    • 2020-12-13
    相关资源
    最近更新 更多