2012-11-05 26 views
0

所以我显示基于选择复选框的图形,并遇到一个小问题。获取所有的ONE属性的实例,而不是只有一个

我目前正在循环并选择第一个图表,即使选中全选复选框时也是如此 - 这意味着我得到了许多相同的第一个图形而不是十个独特的图形。

正如您将在下面的代码中看到的,我用的是以前的行注释掉:完美在Firefox

//var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value; 

只能 - 它会显示所有图表正确等,但不工作在Chrome/IE中,由于它尝试访问元素的方式。

我与这两条线取代了它:

$el = $('#counterTreeviewUL'+idTreeview).first(); 
var fnInstance = $el.find("input").attr("onclick"); 

我有原因的一切取而代之的是在所有三个浏览器功能(在IE或Chrome没有错误了)这两条线,然而的只有图中显示的是第一个找到的 - 如果选择了三个元素,那么将显示第一个图的3个版本,而不是3个独特的图。

完整的代码的下方,什么样的元素包含console.logs是低于:元素

for (var i=0;i<$('#counterTreeviewUL'+idTreeview)[0].children.length;i++) 
{ 

if (!$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked) 
{ 
     $('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked=true; 


//var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value; 

     $el = $('#counterTreeviewUL'+idTreeview).first(); 
     var fnInstance = $el.find("input").attr("onclick"); 


     fnInstance=fnInstance.substr(15).substr(0,fnInstance.length-2); 

     var flagsInstance=fnInstance.split(new RegExp(",")); 

     var graph = { 
       id: seqId, 
       entityName: flags[6].substr(1).substr(0, flags[6].length - 2), 
       entity: flags[5].substr(1).substr(0, flags[5].length - 2), 
       idCounter: flags[4], 
       counterName: flags[3].substr(1).substr(0, flags[3].length - 2), 
       ivmanager: flags[7].substr(1).substr(0, flags[7].length - 2), 
       chart: null, 
       pointsToShowX: null, 
       borneInf: null, 
       unite: "", 
       idInstance: flagsInstance[2].substr(1).substr(0, flagsInstance[2].length - 2), 
       instanceName: flagsInstance[3].substr(1).substr(0, flagsInstance[3].length - 2), 
       listPdsNull: new Array(), 
       countInstance: idTreeview + "_" + i, 
       countGraph: -1 
      }; 

     seqId++;   
     graphs[graphsLastId]=graph;  
     graphsLastId++; 
    } 
} 

Console.logs:

enter image description here

任何因为我花了几个小时试图解决(另一个以前雇员的)代码,所以帮助会很大。

我基本上只需要这一行的浏览器的版本 -

var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value; 
+0

您似乎仍然混合使用jQuery和纯DOM方法。 – Bergi

+0

@Bergi这不是我的代码,我对你为什么这样做是困惑的。我会去改变所有的东西给JQuery,但现在这是唯一的'错误'我已经离开和截止日期的调用。 。只是不知道如何以IE和Chrome接受的方式复制注释行。 – lifetimes

+0

对于开始,您可以使用$('#counterTreeviewUL'+ idTreeview +'input)缩短您的复选框选择器[类型= “复选框”]:检查')'。 – kayen

回答

1

原文:

fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes1.value; 

我的建议:

var changedIforPsedoSelctor = i+1; 
var nthChild = ":nth-child("+changedIforPsedoSelctor+")"; 
var fnInstance = $('#counterTreeviewUL'+idTreeview).children(nthChild).children(":first-child").attr("onclick"); 

我认为应该这样做,但是如果你为这个问题提供了HTML标记,回答你的问题会容易得多。我还假设属性[1]等于选择器中的“onclick”。

+0

是的,如果你看看我的console.logs,它会显示声明的每个部分的含义,所以是的,它是单击选择器。这个代码,但是我给了我一个错误“fnInstance没有定义” – lifetimes

+0

这可能是因为我忘了把一个varInfront,现在编辑:) – tajen

+0

我已经添加了var但仍未定义:/它似乎使它'未定义'为fnInstance =未定义在它下面的控制台日志中。 – lifetimes

相关问题