使用jquery在悬停上添加背景颜色和边框到表格行

前端之家收集整理的这篇文章主要介绍了使用jquery在悬停上添加背景颜色和边框到表格行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有人知道如何在鼠标悬停在行上时将边框添加到具有不同背景颜色的表格行的边框?

我已经能够改变行的背景颜色:

  1. $(document).ready(function() {
  2. $(function() {
  3. $('.actionRow').hover(function() {
  4. $(this).css('background-color','#FFFF99');
  5. },function() {
  6. $(this).css('background-color','#FFFFFF');
  7. });
  8. });
  9. });

但是我无法添加边框颜色.我意识到边框不能直接应用到表行标签,但我希望有人知道一些jQuery巫术魔法,可以在所选行中找到表格单元格,并为创建边框应用一些样式.

谢谢!

解决方法

  1. $(function() {
  2. $('tr').hover(function() {
  3. $(this).css('background-color','#FFFF99');
  4. $(this).contents('td').css({'border': '1px solid red','border-left': 'none','border-right': 'none'});
  5. $(this).contents('td:first').css('border-left','1px solid red');
  6. $(this).contents('td:last').css('border-right','1px solid red');
  7. },'#FFFFFF');
  8. $(this).contents('td').css('border','none');
  9. });
  10. });

猜你在找的jQuery相关文章