Simple Javascript XML Slideshow
I can't seem to figure out why this isn't working. I just have two simple functions: one that loads the image into an img node, and one that pluses an i variable. The second function fires after a timer event, + the count, and then fires the image() function again. Except it's not working.
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    //XML Loaded, create the slideshow
    alert(xml开发者_开发技巧http.responseText);
    var slideShow = document.getElementById('slideShow');
    var items = [];
    var nl = xmlhttp.responseXML.getElementsByTagName('image');
    var i = 0;
    var t;
    function image() {
        var slideShowImg = document.getElementById('slideShowImg');
        var nli = nl.item(i);
        var src = nli.getAttribute('src').toString();
        var width = parseInt(nli.getAttribute('width').toString());
        var height = parseInt(nli.getAttribute('height').toString());
        var imgNode = document.createElement('img');
        imgNode.setAttribute('src', src);
        imgNode.setAttribute('height', height);
        imgNode.setAttribute('width', width);
        slideShowImg.appendChild(imgNode);
        t = setTimeout("nextImage()", 5000);
    }
    function nextImage() {
        i++;
        image();
    }
    image();
}
This line looks very suspicious:
t = setTimeout("nextImage()", 5000);
Try this instead:
t = setTimeout(nextImage, 5000);
Move the function definitions out of the if statement.
 加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论