我正在尝试根据是否包含字符来设置表格中的表格单元格在网址中与否(不要问,处理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");
});
答案 0 :(得分: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");
});
答案 1 :(得分:0)
如果我可能会问一个愚蠢的问题,为什么不在服务器端处理时分配类而不是用jquery执行此操作?它没有动态变化,对吗?