我是靠谱客的博主 现实胡萝卜,这篇文章主要介绍jquery怎样选择除了最后一列的其它元素,现在分享给大家,希望可以做个参考。

本教程操作环境:windows7系统、jquery3.2.1版本、Dell G3电脑。

jquery怎样选择除了最后一列其它的元素

我们可以通过:last-child选择器和:not(selector) 选择器来选择除了最后一列的元素。

示例如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $('tr td:not(:last-child)').css('background-color','red'); }); }); </script> </head> <body> <button>选择除了最后一列的所有元素</button> <table border="1"> <tr> <td>one</td><td>two</td><td>three</td><td>last</td> </tr> <tr> <td>blue</td><td>red</td><td>green</td><td>last</td> </tr> <tr> <td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>last</td> </tr> </table> </body> </html>
登录后复制

输出结果:

39.png

点击按钮后:

40.png

相关视频教程推荐:jQuery视频教程

以上就是jquery怎样选择除了最后一列的其它元素的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是现实胡萝卜最近收集整理的关于jquery怎样选择除了最后一列的其它元素的全部内容,更多相关jquery怎样选择除了最后一列内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部