首页 > 解决方案 > jQuery addClass() 方法

问题描述

我正在尝试通过更新其 CSS 类来突出显示具有特定项目 ID(在第一列中)的表行,但它不起作用:

.inactive {
  background-color: "red";
}

每当发生特定事件时,我的代码都会调用以下 JavaScript 函数:

function highlight_item(item_id){
  var tableRow = $("#itemsTable tr td:first-child").filter(function() {
    return $(this).text() == item_id
  }).parent();
  tableRow.addClass("inactive")
}

奇怪的是,如果我addClass()

tableRow.css("backgroundColor", "red")

我在这里做错了什么?

标签: javascriptjquerycss

解决方案


从“红色”中删除引号。采用.inactive { background-color: red; }


推荐阅读