-2

i am facing some difficulty with getting the height of the dynamically loaded div image.. sometimes , it gives the correct height but sometimes it gives zero .. here is my code

$.ajax({
                        type: "POST",
                        url: "images.php",
                        data: dataStr,
                        cache: false,
                        async : false,
                        success: function(data)
                        {

                        $('.up').empty();
                        $(".up").html(data);
                        alert($(".loadimg").height());

                          }
                         });

here is what i am appending

echo '<div class="imagediv">
    <img src="default.jpg"  class="loadimg" />
        </div>  ';
4

2 回答 2

0

您可以像这样尝试 .delegate() :

$(".up").delegate("img", "load", function() {
  alert($(".loadimg").height());
})

                $.ajax({
                type: "POST",
                url: "ajax.php",
                async:false,
                success: function(data)
                  {
                    $('.up').empty();
                    $(".up").html(data);
                  }
                 }); 
于 2012-09-15T09:43:21.483 回答
0

利用$(".loadimg").load(function(){ alert($(".loadimg").height()); });

尝试这个

                $.ajax({
                    type: "POST",
                    url: "images.php",
                    data: dataStr,
                    cache: false,
                    async : false,
                    success: function(data)
                    {
                        $('.up').empty();
                        $(".up").html(data);

                        $(".loadimg").load(function(){
                            alert($(".loadimg").height());
                        });
                      }
                     });    
于 2012-09-15T09:17:36.127 回答