3

我正在尝试根据是否包含字符 | 来设置表格中的表格单元格样式。在网址中与否(不要问,与 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");
        });
4

2 回答 2

2

这似乎有效。

$(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");  
}); 
于 2009-06-09T15:35:10.760 回答
0

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

于 2009-06-09T15:20:00.790 回答