删除的内容(Delete contents of )

编程入门 行业动态 更新时间:2024-10-26 18:16:51
删除的内容(Delete contents of )

我是javascript / jquery的新手。 我有一个具有索引列(0,1,2,3等)的表。 我想使用javascript删除表的那一部分。 我尝试使用after()和replaceWith(),但无法真正做到正确。

css类是.jobStats。 我想在下面的代码中只删除th标签的内容。

<tr> <th>0 </th> <td> 2015-06-02</td> <td> ARCA</td> <td> FAILED</td> <td>2015-06-03 10:30:51.573000</td> <td> NaT</td> <td> NaT</td> <td> NaN</td> <td> NaN</td> <td> NaN</td> <td> 8704</td> <td> 223226518</td> <td> NaN</td> <td> NaN</td> </tr>

有关如何实现这一点的任何想法?

提前致谢!

I am new to javascript/jquery. I have a table that has an index column (0,1,2,3 etc). I would like to delete that part of the table using javascript. I tried to use after() and replaceWith() but couldn't really get it right.

The css class is .jobStats. I would like to ONLY remove contents of th tag in the code below.

<tr> <th>0 </th> <td> 2015-06-02</td> <td> ARCA</td> <td> FAILED</td> <td>2015-06-03 10:30:51.573000</td> <td> NaT</td> <td> NaT</td> <td> NaN</td> <td> NaN</td> <td> NaN</td> <td> 8704</td> <td> 223226518</td> <td> NaN</td> <td> NaN</td> </tr>

Any thoughts on how I can achieve that?

Thanks in advance!

最满意答案

只需使用remove()

$('.jobStats').remove();

如果你想保留.jobStats并想要删除它的子.jobStats ,请使用empty()

$('.jobStats').empty();

更新

我只想删除表中th标签的内容。

$('th').empty();

将删除儿童和文本

此方法不仅删除子(和其他后代)元素,还删除任何文本

Just use remove()

$('.jobStats').remove();

If you wish to keep .jobStats and want to remove its children, use empty()

$('.jobStats').empty();

Update

I only want to remove the contents of the th tag in the table.

$('th').empty();

will remove both children and text

This method removes not only child (and other descendant) elements, but also any text

更多推荐

本文发布于:2023-07-28 23:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   Delete   contents

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!