尝试在加载时加载页面而不是单击

时间:2011-02-12 02:29:40

标签: javascript jquery load

我正在使用此代码:

$( 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”的页面

1 个答案:

答案 0 :(得分: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>
相关问题