2

我试图到处寻找解决方案,但我似乎无法理解如何正确完成。本质上,我有一个要从中提取数据的 XML。我希望页面加载第一个条目,一旦用户单击前进按钮,我希望它遍历 XML 直到它到达末尾。后退按钮也是如此。

    $(document).ready(function(){
        var name = [];
        var description = [];
        var html_screenshot_01 = [];
        var html_screenshot_02 = [];
        var site_link = [];
        var source_link = [];
        var demo_link = [];

        $.ajax({
            type: "GET",
            url: "projects_html.xml",
            dataType: "xml",
            success: function(xml) {
                $(xml).find('name').each(function(){ name.push($(this).text()); });
                $(xml).find('description').each(function(){ description.push($(this).text()); });
                $(xml).find('html_screenshot_01').each(function(){ html_screenshot_01.push($(this).text()); });
                $(xml).find('html_screenshot_02').each(function(){ html_screenshot_02.push($(this).text()); });
                $(xml).find('site_link').each(function(){ site_link.push($(this).text()); });
                $(xml).find('source_link').each(function(){ source_link.push($(this).text()); });
                $(xml).find('demo_link').each(function(){ demo_link.push($(this).text()); });                   

                $(xml).find('projects').each(function(){


                    $('#name').empty().append(name[0]);
                    $('#description').empty().append(description);
                    $("img#html_screenshot_01").attr("src", html_screenshot_01);
                    $("img#html_screenshot_02").attr("src", html_screenshot_02);
                    $("a#site_link").attr("src", site_link);
                    $("a#source_link").attr("src", source_link);
                    $("a#demo_link").attr("src", demo_link);    

                    $('a#site_link').filter(function() {return $.trim($(this).text()) === ''}).css("visibility", "hidden")
                    $('a#source_link').filter(function() {return $.trim($(this).text()) === ''}).css("visibility", "hidden")                    
                    $('a#demo_link').filter(function() {return $.trim($(this).text()) === ''}).css("visibility", "hidden")
                });
            }
        });
        $("#next").click(function() {
            var i = 0;
            i++;
            $('#name').empty().append(name[i]);
            return false;
        });
        $("#back").click(function() {
            alert('back');
        });
    });
4

1 回答 1

0

将您 var i = 0;移出下一次点击事件

.
.

var i = 0;
$("#next").click(function() {
.
.
.
于 2012-06-15T05:17:23.250 回答