使用jQuery更改文本区域Spotfire的背景颜色

时间:2017-02-04 18:49:56

标签: jquery html css spotfire

我在spotfire的文本区域中有两个计算值。我想使用jQuery根据一个值是否高于另一个值来更改文本区域背景的颜色。我已经设置但它无法正常工作。它似乎甚至没有执行。这是HTML。

 <body id = wrapper>
 <SPAN id = thisyear><SpotfireControl id="2f97a6afc3e64512977dd042a7e32351"     /></SPAN>

 <SPAN id = lastyear ><SpotfireControl id="f98415c74eb34cedbab057f763788bc6" /></SPAN>
 </body>

最高计算值(在今年的id中)值77750,底部计算值具有(在id lastyear中)44086

这个想法是,当过滤器更改值时,我希望背景颜色发生变化。这是目前无效的jQuery:

$( "#thisyear" ).change(function() {
   var thisyearval = ParseInt($("#thisyear").val());
   var lastyearval = ParseInt($("#lastyear").val());
   if (thisyearval > lastyearval){
       $("#wrapper").css("background-color", "#009900")
       } else{$("#wrapper").css("background-color", "#FF0000")}
});

我是jQuery的新手,所以非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

我最终搞清楚了这个。这是html:

<body >
<div id = wrapper>
<div id = thisyear><SpotfireControl id="d644de4c97c440fbb78c561f190e5a47" />   </div>

<div id = lastyear ><SpotfireControl id="f98415c74eb34cedbab057f763788bc6" /></div>
</div>
</body>

完成这项工作的jQuery:

setInterval(function() {
   var thisyearval = parseInt($("#thisyear").text(),10)
   var lastyearval = parseInt($("#lastyear").text(),10)


   if (thisyearval > lastyearval){
      $("#wrapper").css("background-color", "#009900")
   } else{$("#wrapper").css("background-color", "#FF0000")}
}, 500);

事实证明,spotfire不支持jQuery中的change函数,所以我使用setInterval()来反复调用函数。

希望这也可以帮助别人。