dygraphs setVisibility(),页面上有多个图

时间:2013-08-06 19:05:53

标签: javascript dygraphs

我一直在使用dygraphs,并且已经使用了一个可以使用复选框的网页来切换页面上可能无限数量的dygraph的可见性。

但是当我添加按钮来全部设置或全部关闭时,我现在卡住了。

我找到了一个我遵循的基本示例:http://dygraphs.com/tests/color-visibility.html,其ID名称为复选框0-3。这适用于一个图,甚至多个图,只要我不必调用复选框的ID。我让整个系统都在重复ID号。

但是,当我添加一个按钮来自动选中该框时,我需要唯一标识的复选框,否则它只会检查并取消选中第一组框。然后,一旦我重命名复选框ID,原始可见性功能就不起作用。

HTML:

<input type=checkbox id=0 onClick="change(this,plotname)" checked=true > A
<input type=checkbox id=1 onClick="change(this,plotname)" checked=true > B
<input type=checkbox id=2 onClick="change(this,plotname)" checked=true > C
<input type=checkbox id=3 onClick="change(this,plotname)" checked=true > D

<input id="all_On" type="button" value="All On" onclick="checkTheBoxes([true, true, true, true],<%= chartnumber %>)">

JS代码:

function change(element,name) {
    name.setVisibility(element.id, element.checked);
  }


  function checkTheBoxes(tfarray,section) {
   for (var j = 0;tfarray.length;j++){

        document.getElementById(j).checked = tfarray[j]
        document.getElementById(j).onclick()
        //I have been using the section input to identify plots with the renamed IDs
      }
 }

我认为问题在于通过更改功能时的“this”调用。当我使用Firebug进行探测时,如果我单击复选框3号,则元素输入#3,这样可行。但是,如果我重命名了像plot2box3这样的ID,那么firebug元素就是输入#plot2box3,我相信setVisibilty函数不知道该怎么做。

问题是,如何保持“this”引用输出正确的元素,同时能够唯一地调用复选框。

谢谢!

0 个答案:

没有答案