0
var contentparanum = 1;
while($(".container").height() < 200){
        paranum++;
        $(".content").append("<p></p>");
        $(".content p:nth-child("+contentparanum+")").load("getcontent.php?paranum="+paranum);
        contentparanum++;
        //use load() to add content into container, when the height of container is over 200px the loop stops
}

問題は、ループが止まらないことです。alert(".container"); を追加しました。ループに入ると、0しか取得できません。コンテナの高さは、whileループが終了した後にのみ取得できるようです。この問題を解決するにはどうすればよいですか?


特定のコードを追加しました

そしてhtmlコードはこちら

  <div class="container">
    <div class="content"></div>
  </div>
4

2 に答える 2

-1
function loadContent(paranum) {
    $("#container").append("<p></p>")
    $("#container").children().last().load("getcontent.php?paranum="+paranum, function() {
        if($("#container").height() < 200) {
            window.setTimeout(loadContent, 0, paranum+1);
        }
    });
    }

$(function() {loadContent(1);});
于 2013-04-14T10:07:37.917 に答える