小弟我要用js从json文件中取值,并输出的html页面,有个有关问题

WBOY
Libérer: 2016-06-13 12:27:22
original
747 Les gens l'ont consulté

我要用js从json文件中取值,并输出的html页面,有个问题
json文件有多个  0.json  1.json  2.json  3.json ...

现在的情况是js可以挨个读取json文件中的内容,但是每次读取新文件的时候之前的文件内容就没了,我想要加载新json文件内容时,保留之前的读出来的内容

求大神!!!

js 为: 

var i = 0; //当前文件头部
window.onload = function () {

    var host = window.location.host; //获取域名
    function getData() {

        //根据页数读取数据
        var filename = i+".json";
        i++;

        $.getJSON("http://bendi.ceshi.com/"+filename, function (data) {
            var $content = $("#content");
                var html ='';
            //  $jsontip.empty();//清空内容
            $.each(data, function (infoIndex, info) {
                html += '

';
            })
            $content.html(html);//显示处理后的数据
        })

    }

    getData();

    function scrollHandler() {
        $("#pullUpB").show();
$("#pullUpA").hide();
    }

    $("#pullUpB").click(function () {
        getData();
        scrollHandler();
    });
}


------解决思路----------------------
你是覆盖了,应该使用追加。
$content.html(html);//显示处理后的数据
改为
$content.append(html);//显示处理后的数据
------解决思路----------------------
 $content.html(html);//显示处理后的数据  遍历一次,把之前的东西覆盖掉了

追加使用append
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!