我要用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 += '
';
html += '';
html += '';
html += '
';
html += '';
html += '' + info[title] + '';
html += '
';
html += '';
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