开发者

Problem with XML parsing using jQuery

The code here is supposed to place Random images from an XML file into layers. It works but only display the first image in the XML instead of taking Random nodes out of the XML file. Does anyone know why this is?

$(function () {
    $.ajax({
    type: "GET",
    url: "myFakeChannelData.xml",
    dataType: "xml",
    success: changeChannel
    });
});

function changeChannel(xml) {
    $开发者_开发知识库('#layer').fadeOut(1000);
    var $limit = 4;
    $(xml).find("Channel").each(function($limit) {  
        var $channel = $(this);
        var image = $channel.attr('image');
        $("#click").click(function () {
            $(".layer-container").empty();
                $(".layer-container").append('<div class="layer1">' + 
            '<img class="" alt=""   src="' + image + '" />' +  '</div></div>');
            $(".layer-container").append('<div class="layer2">' + '<img class=""                     alt=""  src="' + image + '" />' +  '</div></div>');
             $(".layer-container").append('<div class="layer3">' + '<img class="" alt=""    src="' +     image + '" />' +  '</div></div>');
            $(".Channel").fadeIn(1000);
            var random = Math.floor(limit * Math.random());
            var myNewChannel = remix(random);
            myNewChannel(random);
        });
    });
}


Could it be because of this typo: Math.floor(limit * Math.random()); instead of Math.floor($limit * Math.random());?


Maybe because of that? var random = Math.floor($limit * Math.random());

$(function() {
    $.ajax({
        type: "GET",
        url: "myFakeChannelData.xml",
        dataType: "xml",
        success: changeChannel
    });
});

function changeChannel(xml) {
    $('#layer').fadeOut(1000);
    var $limit = 4;
    $(xml).find("Channel").each(function($limit) {
        var $channel = $(this);
        var image = $channel.attr('image');
        $("#click").click(function() {
            $(".layer-container").empty();
            $(".layer-container").append('<div class="layer1">' + '<img class="" alt=""   src="' + image + '" />' + '</div></div>');
            $(".layer-container").append('<div class="layer2">' + '<img class=""                     alt=""  src="' + image + '" />' + '</div></div>');
            $(".layer-container").append('<div class="layer3">' + '<img class="" alt=""    src="' + image + '" />' + '</div></div>');
            $(".Channel").fadeIn(1000);
            var random = Math.floor($limit * Math.random());
            var myNewChannel = remix(random);
            myNewChannel(random);
        });
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜