firefox几乎崩溃了这段代码。它似乎工作但不是真的

时间:2011-05-03 10:51:24

标签: javascript firefox

window.onload = raknaUtMedelvarde;

function raknaUtMedelvarde(){

    var tabell = document.getElementById("temperaturtabell");
    var rader = tabell.getElementsByTagName("tr");

    for (var i = 0; i < rader.length; i++){
        var tabellceller = rader[i].getElementsByTagName("td");
        //alert(tabellceller.length);
       //räkna ut medelvärde
        var medel = medelVarde(tabellceller);
        //alert(medel);
        var medelText = document.createTextNode(medel);
        var medelElement = tabellceller [tabellceller.length - 1];
        medelElement.appendChild(medelText);


    }
}

function medelVarde(celler){
    var summa = 0;
    for (var i = 1; i < celler.length - 1; i++){

         var nuvarandeVarde = celler[i].firstChild.nodeValue;
         summa = summa + parseInt(nuvarandeVarde);
    }
    return summa / 5;
}
// code behind "visa värde" (show the value)
//I think here somewhre is the problem?

function hitta(){

    var varde = parseInt(document.getElementById("varde").value);
   var tabell = document.getElementById("temperaturtabell");
    var rader = tabell.getElementsByTagName("tr");

    for ( var i = 0; i < rader.length; i++){

        var tabellceller = rader[i].getElementsByTagName("td");
       // checkpoint to see is the values is >= then the enter value
        if(haVarde (varde, tabellceller))
           rader[i].className = "emp";


    }
}

// boolean method to check the value
function haVarde(varde, celler){
    var harVarde = false;
    var sum = 0;
    for (var i = 1; i = celler.length -1; i++){

        var nuvarandevarde = parseInt(celler[i].firstChild.nodeValue);
            if ( nuvarandevarde  >= varde)
            {
                harVarde = true;
                celler[i].className = "emptd";
            }
    }
    return harVarde;
}

你好!

我正在写这段代码。我试着用表中的总数据检查值。 FF开始崩溃有点说..我有问题不知道在哪里看看消息:http://dl.dropbox.com/u/3632213/what.jpg ... mm,mm无法理解消息...任何建议超过欢迎! :)

1 个答案:

答案 0 :(得分:2)

这一行:

for (var i = 1; i = celler.length -1; i++){

会导致无限循环。

你可能意味着&lt; =?