简体   繁体   English

使用基于值的jQuery代码更改SharePoint列表字段的颜色?

[英]Change SharePoint list field color using jQuery code base on value?

I am working with SharePoint list and I need to change the Number field color if it is greater than 60. 我正在使用SharePoint列表,如果大于60,则需要更改Number字段颜色。

I tried to change the code below but it didn't work 我试图更改下面的代码,但是没有用

This is my code which didn't work (I tried to use gt) 这是我的代码不起作用(我尝试使用gt)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"type="text/javascript"></script><script>
$(document).ready(function(){
$Text = $("td .ms-vb2:gt('60')").filter(function() {
return $(this).text() == "td .ms-vb2";})
$Text.css("background-color", "#00FF66");
}); 
</script>

See if these two examples help you: 查看以下两个示例是否对您有帮助:

$(document).ready( function(){

  // option 1

  function tdColor(){
    $( "td:gt(8)" ).css( "backgroundColor", "#00FF66" );
  }
  tdColor();


  //option 2
  function tdColor2(){

    $('td').each(
      function(){
        $("td .ms-vb2:gt(8)").css( "backgroundColor", "#00FF66" );
    });

  }
  tdColor2();

});

Full code here: http://codepen.io/anon/pen/grRBmx 完整代码在这里: http//codepen.io/anon/pen/grRBmx

It's best to use var when declaring variables. 声明变量时最好使用var。

Also bare in mind that if the list is dynamically generated jQuery is not working. 还请记住,如果列表是动态生成的,则jQuery无法正常工作。 In this case it's worth having a look at live() function as well. 在这种情况下,还值得一看live()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM