2011-02-12 71 views
1

我使用這個代碼:試圖加載上的加載頁面,而不是點擊

$(document).ready(function() { 
    $('a.dynamicLoad').click(function(e) { 
     e.preventDefault(); // prevent the browser from following the link 
     e.stopPropagation(); // prevent the browser from following the link 

     $('#MainWrapper').load($(this).attr('href') , function() { 
      /* Content is now loaded */ 
      ThumbnailScroller("tsv_container","vertical",10,800,"easeOutCirc",0.4,500); 
     }); 
    }); 
}); 

與此相伴:

<li><a href="Help.html" class="dynamicLoad">HELP</a></li> 

要鏈接被點擊時加載的頁面。

我想知道如何添加到當前的腳本,以便我可以在頁面加載時加載頁面,同時保持它現在的工作方式?我想加載一個名爲「Homepage.html」頁面

+0

一個更好的想法可能是如果在用戶第一次看到它時在頁面上需要它,那麼在服務器端執行該操作,在這種情況下可能不適用的任何原因? – 2011-02-12 02:49:36

+0

我該怎麼做? – WillingLearner 2011-02-12 11:20:28

回答

1

這應做到:

<script type="text/javascript"> 
jQuery(function() { 
    jQuery('#MainWrapper').load('Homepage.html'); 
}); 
</script> 

或者,如果你仍然需要回調:

<script type="text/javascript"> 
jQuery(function() { 
    jQuery('#MainWrapper').load('Homepage.html', function() { 
     ThumbnailScroller('tsv_container','vertical',10,800,'easeOutCirc',0.4,500); 
    }); 
}); 
</script>