在jquery中选择更大的索引
下面的代码选择 TD #5 到 TD #8 ,但我想选择 TD #2 到 TD #4 。
如何做到这一点?帮我
<table border="1">
<tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>
<tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>
<tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>
</table>
<script>$("td:gt(4)").css("text-decoration", "line-through");</script>
This below code selects TD #5 to TD #8 , but I want select TD #2 to TD #4.
How to do this? Help me
<table border="1">
<tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>
<tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>
<tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>
</table>
<script>$("td:gt(4)").css("text-decoration", "line-through");</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您只需为此目的修改自己的代码即可..
$("td:lt(5)").css("text-decoration", "line-through");
用于编辑的问题
simply you can modify your own code for that purpose..
$("td:lt(5)").css("text-decoration", "line-through");
for edited question
对于编辑后的问题:
For the edited question:
你只是这个意思吗?
或者你想获取单元格的值?在特殊情况下,情况则非常不同。
Do you simply mean this?
Or are you trying to get the value of the cell? In chich case, it is very different.
好吧,您可以使用
:not()
进行反向选择。演示
但
:lt()
将是完美的。$("td:lt(5)").css()
well, you could do a reverse selection by using the
:not()
.demo
but
:lt()
would be perfect.$("td:lt(5)").css()
如果您想在特定条件之间选择数据,您可以使用多个选择器,如下所示:
它将选择 TD #2 到 TD #4。
希望它能有所帮助..
If you want to select data between specific condition you can use multiple selector like this:
It will select TD #2 to TD #4.
Hope it can help..