且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当我将鼠标悬停在HTML表格上时,更改单元格的颜色

更新时间:2023-10-31 22:24:28

在CSS中:

td:hover {
  background-color: #ff0000;
  color: #000000;
}

或者您可以使用JavaScript / jQuery:

Or you can use JavaScript/jQuery:

$(document).ready(function() {
  $("td").hover(
    function() {
      $(this).css('background-color', '#ff0000');
      $(this).css('color', '#000000');
    }, 
    function() {
      $(this).css('background-color', 'none');
      $(this).css('color', 'black'); // or whatever your original color was
    }
  );
});