2012-11-05 29 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

相關問題