如何删除每一行的第一列?

Pho*_*own 11 jquery

我在尝试从每一行中删除第一列时遇到问题.我有一个感觉,这是我对jquery的理解.

我尝试了以下内容.

$("table:eq(2) tr td:first").remove() // this only removed the first cell

$("table:eq(2) tr td:first").each.remove() // didn't notice a difference
Run Code Online (Sandbox Code Playgroud)

我做错了什么想法?

Kar*_*rim 17

尝试使用td:first-child而不是td:first

有关更多信息,请参阅此页面:http: //api.jquery.com/first-child-selector/

PS为您的jQuery选择器提出的一些建议:

  1. 使用表id或类而不是索引标识,因为如果在DOM中移动表,则选择器将中断

  2. 我很确定你不需要"tr"

所以:

 $("#myTable td:first-child").remove()
Run Code Online (Sandbox Code Playgroud)