Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载多个动态图像 函数加载页(第页){ //每页包含10幅图片 var endp=第10页; //清空包含图片的主容器 $(“#容器”).empty(); //重写页面菜单 对于(j=1;j_Javascript_Jquery_Html - Fatal编程技术网

Javascript 加载多个动态图像 函数加载页(第页){ //每页包含10幅图片 var endp=第10页; //清空包含图片的主容器 $(“#容器”).empty(); //重写页面菜单 对于(j=1;j

Javascript 加载多个动态图像 函数加载页(第页){ //每页包含10幅图片 var endp=第10页; //清空包含图片的主容器 $(“#容器”).empty(); //重写页面菜单 对于(j=1;j,javascript,jquery,html,Javascript,Jquery,Html,,可以向图像标记添加onload属性。 在这里,您将调用一个函数,如imageLoaded(),该函数递增imageCounter。如果imageCounter与您添加的图像数量匹配,则将调用wall.reload()。代码可能与以下代码类似: function LoadPage (page) { // each page contains 10 pictures var endp = page*10; // Empty the main container that contains

,可以向图像标记添加onload属性。 在这里,您将调用一个函数,如imageLoaded(),该函数递增imageCounter。如果imageCounter与您添加的图像数量匹配,则将调用wall.reload()。代码可能与以下代码类似:

function LoadPage (page) {
// each page contains 10 pictures
    var endp = page*10;
// Empty the main container that contains the pictures
    $('#container').empty();
// Rewrite the Page Menu
    for (j=1;j<Math.abs(len/10);j++) {
        $('#container').append("<a href='javascript: LoadData("+j+")'>"+j+"</a>");
    }
// Add the image containers containing images
    for (i=endp-10;i<endp;i++) {
            $('#container').append("<div class='container' id="+i+" >");
    $('#'+i).append("<img src="+x[i].getElementsByTagName('URL')[0].childNodes[0].nodeValue+" width='200'>");
        $('#container').append("</div>");
    }
// Have to call a function ' wall.reload(); ' once all the pictures are loaded!
    setTimeout(function(){
    if (wall) { wall.reload(); }
            },2000);
}
在图像标签中:

var imagesLoaded = 0;
function imageLoaded(){
  imagesLoaded++
  if(imagesLoaded == numberOfImages)
    wall.reload();
  }
}

功能加载页(第页){
//每页包含10幅图片
var endp=第10页;
//清空包含图片的主容器
$(“#容器”).empty();
//重写页面菜单

对于(j=1;jthanks-alot-Michael。它起了作用。但是现在又出现了一个新问题。一旦I$('#con')。empty()主容器并将new.conainter添加到主容器中,.container上固有的jQuery事件(如单击和悬停)停止工作。这是一种奇怪的行为。知道吗?如果删除DOM元素,它将丢失所有事件。只需在DOM中插入新元素,即使使用相同的类,也不会自动获得单击处理程序。Y您必须在插入新内容后再次调用添加事件处理程序的函数。
<img src="asdf.jpg" onload="imageLoaded()">
function LoadPage (page) {
// each page contains 10 pictures
    var endp = page*10;
    // Empty the main container that contains the pictures
    $('#container').empty();
    // Rewrite the Page Menu
    for (j=1;j<Math.abs(len/10);j++) {
        $('#container').append("<a href='javascript: LoadData("+j+")'>"+j+"</a>");
    }

    // count of the loaded images
    var counterLoaded = 0;
    function waitReload(){
       counterLoaded++;
       // if all 10 images loaded
       if (counterLoaded == 10){
          if (wall){
             wall.reload();
          }
       }
    }

    // Add the image containers containing images
    for (i=endp-10;i<endp;i++) {
        $('#container').append("<div class='container' id="+i+" >");
        var img = document.createElement('img');
        img.src = x[i].getElementsByTagName('URL')[0].childNodes[0].nodeValue;
        img.setAttribute('width', '200');
        $('#'+i).append(img);
        $('#container').append("</div>");
        // if image loaded - increment loaded images counter
        img.onload = waitReload;
    }
 }