0

我对 SharePoint 自定义场景还很陌生,但是已经掌握了一些 javascript,它们将根据单元格的值更改 SP 列表中单元格的背景颜色。

这在普通视图上工作正常,但任何分组的东西都不起作用,我相信这与页面加载的顺序有关。有没有办法将 javascript 应用于分组并设置为默认折叠的视图?

我从去年看到另一个线程有类似的查询,但似乎没有解决方案。

提前谢谢了!!!

这是我用于单元格颜色更改的代码:

<script type="text/javascript" language="javascript">   
  var x = document.getElementsByTagName("TD") // find all of the TDs
  var i=0;
  for (i=0;i<x.length;i++)
  {
 if (x[i].className=="ms-vb2") //find the TDs styled for lists
  { 

if (x[i].innerHTML=="Green" && x[i].cellIndex==10)
  {
    x[i].style.backgroundColor='forestgreen'; // set the background color
    x[i].style.color='Black'; //set the font color
  }

if (x[i].innerHTML=="Amber" && x[i].cellIndex==10)
  {
    x[i].style.backgroundColor='Goldenrod'; // set the background color
    x[i].style.color='Black'; //set the font color
  }

if (x[i].innerHTML=="Red" && x[i].cellIndex==10)
  {
    x[i].style.backgroundColor='Firebrick'; // set the background color
    x[i].style.color='black'; //set the font color
  }
 }
}
</script>
4

1 回答 1

0

也许在您的情况下,为给定列自定义 CSS 样式会容易得多。您可以定义扩展 ms-vb2 类的新 CSS 规则,但仅适用于第 10 列。使用 CSS 选择器可以轻松实现这一点。

例如,找到适用于该单元格的 CSS 样式表,并定义一个新规则:.ms-vb2:nth-child(10)[innelHtml='Red']{ Background-color:firebrick; 颜色:黑色 }

然后,只要您的表格单元格可见,就会应用 CSS。

于 2012-08-12T12:23:16.523 回答