代码之家  ›  专栏  ›  技术社区  ›  Mark

使用jQuery设置表格单元格的样式

  •  3
  • Mark  · 技术社区  · 17 年前

    我试图根据url中是否包含字符|来设置表中的表单元格样式(不要问,处理SharePoint)。

    样本HTML;

    <table>
    <tr>
    <td class="ms-cal-workitem">
    <table>
    <tr>
    <td class="ms-cal-monthitem">
    <a href="http://localhost:4657/1">Event 1</a>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td class="ms-cal-workitem">
    <table>
    <tr>
    <td class="ms-cal-monthitem">
    <a href="http://localhost:4657/1|435348578-kfsd-sdfsf-sfsf-324ewwer">Event 2</a>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    

    在任何具有ms cal workitem类的表格单元格中,包含超链接的单元格的背景色应为红色。唯一的例外是任何表单元格,其类为ms cal monthitem,包含在其href属性中包含字符|的超链接。

    到目前为止我所拥有的;

            $(document).ready(function() {
                $("td.ms-cal-workitem:has(a[href*='|'])").css("background-color", "#ffff99");
                $("td.ms-cal-workitem:has(a:not[href*='|'])").css("background-color", "#ffcc33");
            });
    
    2 回复  |  直到 14 年前
        1
  •  2
  •   Patrick McElhaney    17 年前

    $(document).ready(function() {
           $("td.ms-cal-monthitem:has(a[href*='|'])").css("background-color", "#ffff99");
           $("td.ms-cal-monthitem:has(a[href]):not(:has(a[href*='|']))").css("background-color", "#ffcc33");  
    }); 
    
        2
  •  0
  •   Jonathan Fingland    17 年前

    如果我可能会问一个愚蠢的问题,为什么不在服务器端处理时分配类,而不是使用jquery?它不是动态变化的,对吗?