简体   繁体   English

页面不会停止加载-javascript

[英]page doesn't stop loading - javascript

what does it mean if the twirly thing in the tab of the page wont stop spinning, ie saying its loading? 如果页面选项卡中的旋转内容不会停止旋转,即表示正在加载,这是什么意思?

i have a php for loop and in each one of these it throws out i have a javascript onload function with a for loop looking to see if that id (from mysql) is in the javascript cookie array. 我有一个PHP for循环,并且在其中的每一个中都抛出了异常,我有一个带for循环的javascript onload函数,以查看该ID(来自mysql)是否在javascript cookie数组中。 hope that makes sense. 希望这是有道理的。 it all works fine but wont stop loading. 一切正常,但不会停止加载。 anyway, i've played around with break and return false which stop the loading but then doesnt give me the results i want. 无论如何,我一直在休息并返回false,这会停止加载,但没有给我我想要的结果。

can anyone point me in the right direction? 谁能指出我正确的方向? thanks 谢谢

this is the javascript function that is being called by an onload in the img tag that each loop created by the php for function is throwing out. 这是img标签中的onload调用的javascript函数,由php为该函数创建的每个循环都被抛出。 n is the id. n是ID。 secondarray is the cookie data put into a readable array. secondarray是放置在可读数组中的cookie数据。

function cookietest(n)
{ 
for (i = 0; i < secondarray.length; i++) 
{ 
if (secondarray[i] == "ca[]="+n  ) document.getElementById(n).src = "saved.png" ;
}
}

Checking length inside a loop is always a killer. 检查循环中的长度始终是杀手er。 And breaking out of a loop at certain point, helps you improve the performance too. 而且在某些时候冲破循环,也可以帮助您提高性能。

function cookietest(n)
{ 

    var l = secondarray.length;
    for (i = 0; i < l i++) 
    { 
        if (secondarray[i] == "ca[]="+n  ) {
          document.getElementById(n).src = "saved.png" ;
          break; //break out of loop it is no longer needed I GUESS
        }
    }

}

PS: I am just answering based on the codes OP provided, the culprit could be others as well. PS:我只是根据提供的OP进行回答,罪魁祸首也可能是其他人。

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

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