そのようなことを試してください:
for (i = 1;i<9;){
$.get(+i+".txt",
function(res){
$("#slide2 .wrapper").text($("#slide2 .wrapper").text() + res);//I expect here that you have a plain text in .txt files and want to see it like a text
});
i++;
};
これにより、すべてのファイルが読み込まれ、コンテンツに追加され$("#slide2 .wrapper")
ます。
の場合.load
、最後にロードされたファイルを取得するのは、その関数がコンテンツをロード中のファイルのコンテンツに置き換えるだけ$("#slide2 .wrapper")
だからです。1.txt が 2.txt より前にロードされるという保証はないことに注意してください。2.txt が 1.txt よりも速く読み込まれ、1.txt のコンテンツが 2.txt のコンテンツの後に表示される可能性があります。
注文を維持したい場合は、次のようなコードを使用できます。
getContent(1);// instead of for loop
});
function getContent(i) {
$.get(+i+".txt",
function(res) {
$("#slide2 .wrapper").text($("#slide2 .wrapper").text() + res);//I expect here that you have a plain text in .txt files and want to see it like a text
if(i < 9)
getContent(i++);
}
);
}
参考までに: jQuery.getと.load。