小弟我要用js从json文件中取值,并输出的html页面,有个有关问题
我要用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 += '' + info["title"] + '
';
html += '
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
