Jquery移动导航功能?

时间:2013-02-21 09:58:41

标签: javascript jquery

我想实现一个jquery移动导航。但是从jquery load()构建我自己的 功能。我看过history.js但很难理解。很高兴看到地址栏中页面的正确网址。请有人帮我推动我朝着正确的方向前进。

1 个答案:

答案 0 :(得分:0)

这是一个简单的History.js示例。

我们的标记。

<!DOCTYPE HTML>
<html>
<head>
    <script src="jquery.js"></script>
    <script src="jquery.history.js"></script>
<title>History.js</title>
</head>
<body>

        <a href="page1.html">Page 1</a>
        <a href="Page2.html">Page 2</a>
     <div id="content">
        <p>Content within this box is replaced with content from
            supporting pages using javascript and AJAX.</p>
    </div>
</body>
</html>

javascript。

$(function() {

            // Note: We are using a capital H instead of a lower 'h'
            var History = window.History; 
            if (!History.enabled) {
                // History.js is disabled for this browser.
                // This is because we can optionally choose to support HTML4 browsers or not.
                return false;
            }

            // Bind to StateChange Event
            History.Adapter.bind(window, 'statechange', function(e) {
                // Note: We are using statechange instead of popstate
                var State = History.getState();
                $('#content').load(State.url + " #content").html();
            });

            $('a').on('click',function(evt) {
                evt.preventDefault();
                History.pushState(null, $(this).text(), $(this).attr('href'));
            });
        });

将该脚本插入头标记或页面底部。基本上pages1.html和page2.html应该包含一个名为content的div,它会使用$('#content').load(State.url + " #content").html();

中的方法加载返回内容

就是这样。