2017-04-20 2 views
1

Dies ist mein Code,Hallo, ich habe die jQuery dynamische Anfügen Tag Fehler

Ich möchte .modal-links oder .modal rechts, um die Größe Aber Funktion nicht funktioniert. Wenn ich in der Browser-Konsole ausgeführt wurde, hat es funktioniert.

Ich denke, dieses Problem durch dynamische Append-Tag verursacht. Was soll ich tun?

Vielen Dank für das Lesen meines Problems.

function getArtworkDetail(artwork_num){ 
    var modalMask = $('<div class="modalMask"></div>'); 
    var modalContent = $('<div class="modalContent"></div>'); 

    $.ajax({ 
     url : "/artwork/profile_portfolio?artwork_num="+artwork_num, 
     type : 'get', 
     success : function(data){ 
      $(modalContent).append(data); 
     },error : function(e){ 
      console.log(e.responseText); 
     } 
    }) 

    $(modalMask).append(modalContent); 
    $('.modal').append(modalMask); 

    $('.modalMask').css('height',$('body').height()+38); 
    console.log($('.detail-left')); 

    if($('.detail-left').height() > $('.detail-right').height()){ 
     $('.detail-right').css('height',$('.detail-left').height()+'px'); 
    }else{ 
     $('.detail-left').css('height',$('.detail-right').height()+'px'); 
    } 
} 

Antwort

3

Bitte beachten Sie, dass Ajax Call standardmäßig asynchronous Anruf ist ... so in Ihrem Fall Code, welche Seite aus success Verfahren ausgeführt werden erst danach bekommt Ihr ajax Anruf Antwort und es wird success Methode von Ihrem ajax Aufruf ausgeführt.

So Lösung ist, dass ... Sie Ihren Code in Ajax success Methode wie folgt setzen müssen.

Setzen Sie Ihren Code in success Methode wie folgt.

$.ajax({ 
    url : "/artwork/profile_portfolio?artwork_num="+artwork_num, 
    type : 'get', 
    success : function(data){ 
     $(modalContent).append(data); 
     $(modalMask).append(modalContent); 
     $('.modal').append(modalMask); 

     $('.modalMask').css('height',$('body').height()+38); 
     console.log($('.detail-left')); 

     if($('.detail-left').height() > $('.detail-right').height()){ 
      $('.detail-right').css('height',$('.detail-left').height()+'px'); 
} 
     else{ 
    $('.detail-left').css('height',$('.detail-right').height()+'px'); 
      } 
     },error : function(e){ 
      console.log(e.responseText); 
     } 
}); 
+0

Danke !! Es klappt! – suk

+0

@suk - Froh, Ihnen zu helfen :-) ... bitte 'accept' die Antwort ... es hilft anderen, die richtige Lösung zu finden .... Danke – prog1011

0

wie folgt verwenden, entfernen Sie zusätzlichen '$'

$.ajax({ 
    url : "/artwork/profile_portfolio?artwork_num="+artwork_num, 
    type : 'get', 
    success : function(data){ 
     modalContent.append(data); 
    },error : function(e){ 
     console.log(e.responseText); 
    } 
}) 
+0

Ich versuche es nicht, aber ich bin wirklich dankbar für Ihre Hilfe :) – suk