2014-09-01 99 views
0

需要你的意見與我的jQuery點擊,顯示加載頁面前的div加載。我測試了代碼,但div加載不顯示。jQuery顯示div加載onclick

這裏是我到目前爲止的代碼:

$(".taskss3").click(function(evt) 
{ 
    $('#status_random').show(); 
    var get_uid = $(this).attr("id"); 

    $("#randomdiv").load("load_auto.php?uid="+ get_uid) 
    { 
     $('#status_random').hide(); 
     $('#randomdiv').show(); 
    } 
}); 

HTML

<div id="status_random"></div> 
<div id="randomdiv"></div> 

CSS

#status_random 
{ 
background: url('../../assets/images/processing.gif'); 
height: 24px; 
width: 24px; 
margin-left: auto; 
margin-right: auto; 
margin-top: 10px; 
margin-bottom: 10px; 
} 

請幫幫忙!

回答

2

您需要使用回調

$(".taskss3").click(function (evt) { 
    $('#status_random').show(); 
    var get_uid = this.id; 

    $("#randomdiv").load("load_auto.php?uid=" + get_uid, function() { 
     //do this in the load callback 
     $('#status_random').hide(); 
     $('#randomdiv').show(); 
    }) 

}); 

在代碼中,你只要load()被稱爲無需等待加載完成隱藏裝載機。