onclick函数Ajax在div上加载一个页面,其中包含历史记录和浏览器中的历史记录

时间:2012-05-03 06:43:37

标签: javascript ajax

onclick函数外部页面加载div中的ajax函数,其历史记录返回浏览器

<script type="text/javascript">   
    jQuery(document).ready(function () {
        jQuery.history.init(pageload);  
        jQuery('a[rel=ajax]').click(function () {
            var hash = this.href;
            hash = hash.replace(/^.*#/, '');
            jQuery.history.load(hash);  
            getPage();
            return false;
        }); 
    });

    function pageload(hash) {
        //if(!hash){
        //  document.location.hash='test4.html';
        //}
        if (hash) getPage();     
    }

    function getPage() {
        var data = 'page=' + encodeURIComponent(document.location.hash);
        jQuery.ajax({
            url: document.location.hash.replace(/^.*#/, ''),    
            type: "GET",        
            data: data,     
            cache: false,
            success: function (html) {  
                jQuery('#content').html(html);              
                jQuery('a[rel=ajax]').removeClass('selected');
                jQuery('a[href=' + window.location.hash + ']').addClass('selected');
            }       
        });
    }    
    </script>

如何更改onClick功能

<a href="#test1.html" rel="ajax">1</a>

0 个答案:

没有答案