ループから追加したい。値を変数に追加してから、その変数を一度追加します。今のようにするとどうなるかというと、jQuery はそのループを通過するたびに追加メソッドを実行します。毎回それをやり続けてあなたを遅くするので、それは悪いことです. ループを通過して、追加したいものを変数に保存することをお勧めします。次に、その変数を 1 回追加します。このような何かがうまくいくはずです:
var appendText = []; //We can define an array here if you need to play with the results in order or just use a string otherwise.
for (var i = 0; i < 4; i++) {
appendText.push("text" + "<br>"); //This adds each thing we want to append to the array in order.
}
//Out here we call the append once
//Since we defined our variable as an array up there we join it here into a string
appendText.join(" ");
$("#sth").append(appendText);
これがこのFiddleで動作しているのを確認して、いじってみましょう。
ここにあなたがチェックすべきいくつかの読み物があります:
http://www.learningjquery.com/2009/03/43439-reasons-to-use-append-correctly