【问题标题】:Style a Specfic Column of a specific Row of a Table为表格特定行的特定列设置样式
【发布时间】:2017-04-04 21:12:09
【问题描述】:

我有

一张桌子


我想要

设置表格特定行的特定 td 样式。


我决定了

要遍历每个row,在每一行中,我会遍历每个td,并检查td 是否等于我要检查的那个。


我试过了

$('#account-table').each(function () {
    $(this).find('td').each(function () {
      var td = $(this);
      if(td.innerText == 'vazogaxan@hotmail.com'){
        $(this).css('color','red');
      }
   
    });
});

我明白了

我无法将该列文本设为红色

任何提示/建议?

【问题讨论】:

    标签: jquery css html-table


    【解决方案1】:

    innerText 是一个普通的 JS 属性,但是你有一个 jQuery 对象并且你试图访问一个不存在的属性。改用text() 方法

     if(td.text() == 'vazogaxan@hotmail.com'){
    

    更多信息:

    http://api.jquery.com/text/

    https://developer.mozilla.org/es/docs/Web/API/Node/innerText

    【讨论】:

    • 这次我更快了:)。很高兴见到你,@Harry
    • 它有效。我会在 2 分钟内接受你的回答。感谢您的帮助。
    猜你喜欢
    • 2012-01-06
    • 1970-01-01
    • 2011-03-17
    • 2021-03-01
    • 2017-07-14
    • 2022-08-11
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    相关资源
    最近更新 更多