简体   繁体   English

jQuery / Javascript - CSS变化的变量

[英]jQuery/Javascript - Variable into CSS change

I'm writing HTML in Java using a servlet and I'm having a problem where scrolling over a DOM object (third party, jqplot) will light up the text for a particular list. 我正在使用servlet在Java中编写HTML,而我遇到一个问题,即滚动DOM对象(第三方,jqplot)将点亮特定列表的文本。 I have HTML (declared before the jQuery): 我有HTML(在jQuery之前声明):

<li id='cap_1'>
  <span>DOG</span>
</li>

And the following code later: 以下代码:

out.println("<script>$('#chart2').bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data) { var x = 'cap_'+pointIndex; alert(x); $(x).css(\"display\",\"none\"); } );</script>");

The alert is triggering and returns correctly (cap_1). 警报正在触发并正确返回(cap_1)。 But the CSS isn't working (i've tried display, background-color, color, etc - nothing worked). 但CSS没有工作(我尝试过显示,背景颜色,颜色等 - 没有任何效果)。

What am I missing? 我错过了什么? jQuery and library declarations are confirmed and the bind is part of the jqplot library. 确认了jQuery和库声明,绑定是jqplot库的一部分。

You need to add # symbol before x . 你需要在x之前添加#符号。

$('#' + x).css(... and so on $('#' + x).css(...等等

Or, where you declare x : 或者,你声明x

... var x = '#cap_' + ...

You are missing the '#' selector: 你错过了'#'选择器:

out.println("<script>
               $('#chart2').bind('jqplotDataHighlight', 
                                  function (ev, seriesIndex, pointIndex, data) { 
                                      var x = '#cap_'+pointIndex; //<-- Here
                                      alert(x); 
                                      $(x).css(\"display\",\"none\"); 
                                  });
            </script>");

您缺少DOG选择器:

out.println("<script>$('#chart2').bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data) { var x = 'li:contains(DOG)'; $(x).css(\"display\",\"none\"); } );</script>");

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

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