如何使用 jQuery 删除表格行
只是想知道如何按 id 选择表行,
例如表行的 id 为“50”,
...我如何选择它(因为我希望在单击时使用 hide() 函数)
Just want to know how to select a table row by id
eg the table row has the id of "50"
...
How can I select this (as I wish to use the hide() function on a click)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
$('tr#50')
选择该行。.click(function(){...})
当您单击该行时运行该函数。$(this)
是选择设置点击处理程序的原始元素(在本例中为“tr#50”选择的元素)的一种方法。显然,.hide()
隐藏了该元素。编辑:正如其他回答者指出的那样,以数字开头的 id 不是一个好习惯,更糟糕的做法是让你的 id 仅是一个数字。您应该将其重命名为
row-50
之类的名称。$('tr#50')
selects the row..click(function(){...})
runs the function when you click on the row.$(this)
is a way of selecting the original element that you set the click handler on (in this case, that selected by "tr#50"). And.hide()
, obviously, hides that element.EDIT: As other answerers point out, it's not good practice to start an id with a number, and even worse practice to make your id only a number. You should rename it to something like
row-50
.写在 Click 事件上
但我建议你不要以 Number 开头,因为这不是一个好的做法......
write this on Click event
But i would suggest you that don't start your id with Number as it's not a good practice ...
不过要小心纯数字的 id
be careful with number-only ids though
要选择具有 id 的元素,只需使用以下选择器:
因此,对于 id 50 的问题,它将是:
To select an element with an id just use the following selector:
So for your problem with the id 50 it would be:
如果您没有表的 ID 并且只想选择第 50 行,则可以使用以下命令选择它:
或
请注意 eq() 从 0 开始,而不是 1。在本例中 eq() 是(50 - 1)
If you don't have an ID of the table and simply wants to select the 50th row, you can select it with:
or
Note that eq() starts on 0, and not 1. There for the eq() in this case is (50 - 1)